【发布时间】:2019-03-24 13:11:20
【问题描述】:
这个问题我已经有 2 周的时间了。我使用Wix's Navigation 在应用程序中导航。我跟着this tutorial 实现了深度链接/通用链接。
我有一个名为BaseScreen 的基类,我在其中保留了教程中的所有深度链接处理程序。这个BaseScreen 看起来像这样:
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,
}
})
}
当应用启动时,它会显示屏幕LoginScreen,它扩展了上面的BaseScreen。杀死应用后,点击邮件中的url,应用首先启动LoginScreen,然后它会重定向到屏幕NewPassword,一切完成后,我会重定向回LoginScreen by:
this.props.navigator.resetTo({
screen: 'LoginScreen',
animated: true,
overrideBackPress: true,
animationType: 'fade',
navigatorStyle: {
navBarHidden: true,
}
})
但是LoginScreen 的Linking.getInitialURL() 仍然接收到旧的url,所以它会再次重定向到NewPassword,这是一个循环。
我也尝试通过:passProps: {} 选项当resetTo LoginScreen 但没有运气。
我想修复它的唯一方法是在 NewPassword 屏幕中完成所有操作后手动清除 initialUrl。 BaseScreen 的监听器应该在那里,因为如果我不杀死应用程序(只是最小化它),监听器应该运行导航到 NewPassword。
Wix 的导航有一个用于 Deeplink 的文档,我尝试将方法 onNavigatorEvent(event) 放入 BaseScreen 但它没有被调用。我不知道我是否错过了什么。
感谢您的宝贵时间。任何想法将不胜感激
【问题讨论】:
-
将 android:launchMode="singleTask" 添加到 AndroidManifest 中的主 .MainActivity stackoverflow.com/questions/45752822/…
标签: android ios react-native deeplink