简体   繁体   English

React Native 深度链接

[英]React Native Deep Linking

I have the following block running on compontentDidMount to detect incoming deep links from a web browser.我在 componentDidMount 上运行以下块以检测来自 Web 浏览器的传入深层链接。

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

My problem is whenever I click a link with the app running in the background, I need to be able to detect the newly clicked link.我的问题是,每当我单击在后台运行的应用程序的链接时,我都需要能够检测到新单击的链接。

i have this function running:我有这个功能运行:

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

However this loads whatever link that was clicked to trigger the app to load in the first place.然而,这会加载任何被点击以触发应用程序加载的链接。

Can anyone help me identify how to detect a link clicked in the browser with the app running in the background?任何人都可以帮助我确定如何检测在后台运行的应用程序在浏览器中单击的链接吗?

Add the eventListener whether it's Android or iOS.添加事件侦听器,无论是 Android 还是 iOS。 The event will fire when the app is in the background.该事件将在应用程序处于后台时触发。 Getting the Linking.getInitialURL() is only necessary for Android.获取 Linking.getInitialURL() 仅适用于 Android。

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

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