Tra*_*Nam 1 android ios react-native deeplink
我已经有两个星期了这个问题。我使用Wix的导航在应用程序中导航。我按照本教程实施了Deeplink / Universal链接。
我有一个称为的基类BaseScreen,其中像教程中一样保留所有的Deeplink处理程序。这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,
}
})
}
Run Code Online (Sandbox Code Playgroud)
应用启动后,将显示LoginScreen扩展BaseScreen上述内容的屏幕。终止该应用程序后,单击邮件中的url,该应用程序LoginScreen首先启动,然后将其重定向到屏幕NewPassword,完成所有操作后,我将LoginScreen通过以下方式重定向回:
this.props.navigator.resetTo({
screen: 'LoginScreen',
animated: true,
overrideBackPress: true,
animationType: 'fade',
navigatorStyle: {
navBarHidden: true,
}
})
Run Code Online (Sandbox Code Playgroud)
但Linking.getInitialURL()的LoginScreen仍然收到旧的URL,所以它会重定向到NewPassword再次,这是一个循环。
我也尝试通过:passProps: {}选项resetTo,LoginScreen但是没有运气。
我猜想解决此问题的唯一方法是在NewPassword屏幕上完成所有操作后手动清除initialUrl 。的侦听器BaseScreen应该在那里,因为如果我不杀死应用程序(只是将其最小化),则侦听器应该正在运行以导航至NewPassword。
Wix的导航中有一个适用于Deeplink的文档,我尝试将方法onNavigatorEvent(event)放入中,BaseScreen但没有被调用。我不知道我是否想念什么。
感谢您的时间。任何想法将不胜感激
当我们再次回到同一页面时,Linking.getInitialURL()为我们提供了相同的网址,要解决此问题,我们可以做一个简单的条件,即不调用DeepLink函数。就像是...
步骤1:首先初始化一个dummyDeepLinkedUrl String。
var dummyDeepLinkedUrl;
Run Code Online (Sandbox Code Playgroud)
步骤2:检查是否存在类似条件,例如deeplinkUrl是否来自Linking.getInitialURL()并且deeplinkUrl不等于dummyDeepLinkedUrl。
if (url && url != dummyDeepLinkedUrl) {}
Run Code Online (Sandbox Code Playgroud)
步骤3:如果不同,则调用Deeplink函数,并将deeplinkUrl分配给dummyDeepLinkedUrl。
this.navigateToRespectivePage(url);
dummyDeepLinkedUrl = url;
Run Code Online (Sandbox Code Playgroud)
最后,这看起来像:
Linking.getInitialURL().then(url => {
if (url && url != dummyDeepLinkedUrl) {
this.navigateToRespectivePage(url);
dummyDeepLinkedUrl = url;
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1061 次 |
| 最近记录: |