繁体   English   中英

React Native 深度链接

[英]React Native Deep Linking

我在 componentDidMount 上运行以下块以检测来自 Web 浏览器的传入深层链接。

    // Search for deep links
    if (Platform.OS === 'android') {
      Linking.getInitialURL().then((url) => {
        this.navigate(url);
      });
    } else {
      Linking.addEventListener('url', this.handleOpenURL);
    }

我的问题是,每当我单击在后台运行的应用程序的链接时,我都需要能够检测到新单击的链接。

我有这个功能运行:

handleAppStateChange = (nextAppState) => {
    if (nextAppState === 'active') {
     if (Platform.OS === 'android') {
       Linking.getInitialURL().then((url) => {
         this.navigate(url);
       });
     } else {
       Linking.addEventListener('url', this.handleOpenURL);
     }
    }
  }

然而,这会加载任何被点击以触发应用程序加载的链接。

任何人都可以帮助我确定如何检测在后台运行的应用程序在浏览器中单击的链接吗?

添加事件侦听器,无论是 Android 还是 iOS。 该事件将在应用程序处于后台时触发。 获取 Linking.getInitialURL() 仅适用于 Android。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM