Home > database >  How to know the address of the deep link that redirected to my app in React Native
How to know the address of the deep link that redirected to my app in React Native

Time:12-09

I have a react app which is redirecting to a React native App with this code:

      <a href="my.app://">go to my app</a>

I want to pass some information to my react native app, so I Need to get the exact address that was called in order to redirect me to the app, how can I accomplish that both in IOS and Android ?

CodePudding user response:

You can use Linking component from RN package https://reactnative.dev/docs/linking#handling-deep-links

Handling Deep Links There are two ways to handle URLs that open your app.

  1. If the app is already open, the app is foregrounded and a Linking 'url' event is fired You can handle these events with Linking.addEventListener('url', callback) - it calls callback({ url }) with the linked URL

  2. If the app is not already open, it is opened and the url is passed in as the initialURL You can handle these events with Linking.getInitialURL() - it returns a Promise that resolves to the URL, if there is one.

  • Related