DeepLink工作正常,但无法使用反应导航导航到目标屏幕

时间:2019-09-24 10:39:44

标签: android react-native react-navigation deep-linking

我在Android上,并且想使用DeepLink通过反应导航打开特定的屏幕。

这是我的清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.samtbook">

<application
        android:name=".MainApplication"
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:allowBackup="false"
        android:theme="@style/AppTheme"
        android:supportsRtl="false"
        android:usesCleartextTraffic="true"
>
    <activity
            android:launchMode="singleTask"
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:scheme="http" android:host="samtbook.me"/>
        </intent-filter>
    </activity>
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
    <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="API_KET"/> // HIDDEN
</application>

这是我使用的链接:

http://samtbook.me/test/

我这样注册了deepLink:

  componentDidMount() {
    Linking.addEventListener('url', this.handleOpenURL);
    }
    componentWillUnmount() {
    Linking.removeEventListener('url', this.handleOpenURL);
    }

    handleOpenURL = (event) => {
    this.navigate(event.url);
    };
    navigate = (url) => {
      this.props.navigation.navigate('TestScreen');
    };

问题是当应用程序不在后台运行时(意味着已死) 我单击链接,它打开了应用程序,但没有导航到预期的屏幕 但是当应用在后台运行时,它会导航

预先感谢

2 个答案:

答案 0 :(得分:2)

使用文档中提到的React导航深层链接:
https://reactnavigation.org/docs/en/deep-linking.html

答案 1 :(得分:1)

检测到HTTP方案为Web URL,只需将您的方案更改为自定义方案(例如“ myapp”),然后将您的URL更改为myapp://samtbook.me/test/祝您好运!