# Deeplinking

To handle deep links please check the react-native [documentation](https://reactnative.dev/docs/linking#handling-deep-links).

On iOS, `Linking.getInitialURL` might return null even when the app was started as a result of a Batch push notification with a deeplink. This is because the iOS Batch SDK opens the deep-link related to your push notification, after the app has already started.

In order to workaround this, you can use the following:

```ts
import { BatchPush } from '@batch.com/react-native-plugin';

BatchPush.getInitialURL().then((url: string | null) => {
  console.log('received initial url', url)
});
```

This is a replacement of `Linking.getInitialURL` that you can use on Android or iOS: `Batch.getInitialURL` first checks if `Linking.getInitialURL` returns something, and then if it doesn't on iOS, it calls a custom native function of this module that gets the first deeplink it has ever seen. Subsequent calls to this native function will return `null` to prevent a future JS reload to see an old initial URL. Because of this, you have to make sure to call this method only once in the app lifetime.

{% hint style="warning" %}
Make sure to also listen for the Linking `url` event in case Batch opens your deep-link after you call getInitialURL.
{% endhint %}

If you are using `@react-navigation` to handle your deeplinks redirects, please don't forget to follow the [Third-party integrations part](https://reactnavigation.org/docs/deep-linking/#third-party-integrations). You can also check our [Github](https://github.com/BatchLabs/Batch-ReactNative-Plugin-Sample/blob/master/app/App.tsx) to find an example of implementation.

### Universal links

If your app handles universal links please follow the [native iOS documentation](/developer/sdk/ios/advanced/deeplinking.md#universal-links) to declare your associated domains. Please ensure you have at least the version 1.18 of the native iOS Batch SDK installed.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.batch.com/developer/sdk/react-native/advanced/deeplinking.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
