问题描述
我有以下域:https://demoproject.com
我想将所有带有 /demo
路径参数的 URL-s 与我在 Android 上的 React Native 应用程序相关联,以便例如 URL https://demoproject.com/demo?a=1&b=2
将被链接,但任何其他具有相同域的 URL,但是将排除不同的路径参数。
现在我像这样使用 React Navigation 5:
const linking = {
prefixes: ['https://demoproject.com'],config: {
DemoScreen: {
path: '/demo/*'
}
}
};
<NavigationContainer linking={linking}>
AndroidManifest.xml
<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="https" />
<data android:host="demoproject.com" />
</intent-filter>
链接本身工作正常,但问题是所有带有前缀 https://demoproject.com
的 URL-s 都被链接,而我只希望链接带有 /demo
路径参数的 URL-s。
我试过了:
-
<data android:host="demoproject.com/demo" />
- 没有链接 URL -
prefixes: ['https://demoproject.com/demo']
- 所有带有https://demoproject.com
域的 URL 都已链接
解决方法
它必须在 IntentFilter 中用 pathPrefix
或 pathPattern
定义:
<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="https" />
<data android:host="demoproject.com" android:pathPrefix="/demo/" />
</intent-filter>
来源:https://developer.android.com/guide/topics/manifest/data-element#path