0

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.

nodabasi
  • 58
  • 6
  • You can use some javascript split concept to extract the code here. url.split('code=')[1]?.trim(); This will give you "123". – Akshay Shenoy Nov 26 '21 at 07:31

2 Answers2

0

You just need to take the params from route

const Example = ({navigation, route})=>{
  const code = route.params.code;
}
jted95
  • 1,084
  • 1
  • 9
  • 23
0

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.

nodabasi
  • 58
  • 6