Reading Url with React Native Deep Linking

575 Views Asked by At

I am using a deep link which sends me to my app in a specific page but I want to read the link it that page. For example: My link is "my app://somepage/code=123", I want to take this code value from url after I open the link.

2

There are 2 best solutions below

0
On

You just need to take the params from route

const Example = ({navigation, route})=>{
  const code = route.params.code;
}
0
On

Ok, I found a method which allows me to run a function whenever I open my page.

 useEffect(() => {
    navigation.addListener('focus', () => {
      getCode();
    });
  }, []);

In the getCode function, I'm using getInitialUrl() function, here is the docs for more info, https://reactnative.dev/docs/linking#getini… You can use this module to collect the coming url and do whatever you want.