Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

Linking.getInitialURL() is not being cleared after used for deeplink

$
0
0

I've had this problem for like 2 weeks. I used Wix's Navigation for navigating around the app. I followed this tutorial for implementing the deeplink/universal link.

I have a base class called BaseScreen where I keep all the deeplink handler like in the tutorial. This BaseScreen would looks like this:

componentDidMount(){    // this handles the case where the app is closed and is launched via Universal Linking.    Linking.getInitialURL()        .then((url) => {          if (url) {            // Alert.alert('GET INIT URL','initial url  '+ url)            this.resetStackToProperRoute(url)          }        })        .catch((e) => {})   // This listener handles the case where the app is woken up from the Universal or Deep Linking   Linking.addEventListener('url', this.appWokeUp);  }  componentWillUnmount(){    // Remove the listener    Linking.removeEventListener('url', this.appWokeUp);  }  appWokeUp = (event) => {    // this handles the use case where the app is running in the background and is activated by the listener...    // Alert.alert('Linking Listener','url  '+ event.url)    this.resetStackToProperRoute(event.url)  }  resetStackToProperRoute = (url) => {    // grab the trailing portion of the url so we can use that data to fetch proper information from the server    let trailing = url.slice(url.lastIndexOf('=') + 1, url.length)    // go to the desired screen with the trailing token grabbed from the url    this.props.navigator.resetTo({      screen: 'NewPassword',      overrideBackPress: true,      passProps: {        token: trailing      },      animated: true,      animationType: 'fade',      navigatorStyle: {      navBarHidden: true,  }})  }

When the app launch, it'll show the screen LoginScreen which extends the BaseScreen above. After killing the app, click the url from the mail, the app launches LoginScreen first, then it'll redirect to the screen NewPassword, and after everything has done, I'll redirect back to LoginScreen by:

this.props.navigator.resetTo({  screen: 'LoginScreen',  animated: true,  overrideBackPress: true,  animationType: 'fade',  navigatorStyle: {    navBarHidden: true,  }})

But the Linking.getInitialURL() of the LoginScreen still receive the old url, so it'll redirect to NewPassword again, and it's a loop.

I've also tried to pass: passProps: {} option when resetTo the LoginScreen but no luck.

I guess the only way to fix it is to clear the initialUrl manually after everything's done in NewPassword screen. The listener for the BaseScreen should be there because if I don't kill the app (just minimize it), the listener should be running to navigate to NewPassword.

Wix's navigation has a doc for Deeplink, I tried putting method onNavigatorEvent(event) into the BaseScreen but it doesn't get called. I don't know if I miss something.

Thank you for your time. Any idea would be appreciated


Viewing all articles
Browse latest Browse all 16750

Trending Articles