【发布时间】:2019-12-24 03:32:25
【问题描述】:
我在 react native 上使用深度链接 android 时遇到问题。并且当应用程序从深层链接触发时应用程序处于前台状态时,应用程序不会在该屏幕上刷新。例如,我想要深度链接到主屏幕,但是当我的前景在个人资料屏幕上时,我的应用程序不会刷新?
这是我的深度链接代码:
async componentDidMount() {
// This for deeplinking
if (Platform.OS === 'android') {
Linking.getInitialURL().then(url => {
this.navigate(url);
});
} else {
Linking.addEventListener('url', this.handleOpenURL);
}
navigate = (url) => {
const { navigate } = this.props.navigation;
const route = url.replace(/.*?:\/\//g, '');
const id = route.match(/\/([^\/]+)\/?$/)[1];
const routeName = route.split('/')[0];
if (id === 'yes') {
alert(id)
}
}
【问题讨论】:
-
在
android的情况下为什么不监听url变化? -
怎么听?在前台,屏幕未刷新。
-
使用android,无法注册这个监听器
Linking.addEventListener('url', this.handleOpenURL);。您有上述if条件。 -
是的,它适用于 iOS 和 Android。但我认为这不是问题。
-
或者更快的你能给我链接或者你有没有经历过与 react native 相同的案例?
标签: android react-native react-native-android deep-linking