# 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](https://doc.batch.com/developer/ios/advanced/deeplinking#universal-links) to declare your associated domains. Please ensure you have at least the version 1.18 of the native iOS Batch SDK installed.
