【问题标题】:How to use React Navigation universal links with path parameters on Android?如何在 Android 上使用带有路径参数的 React Navigation 通用链接?
【发布时间】:2021-01-11 15:24:44
【问题描述】:

我有以下域:https://demoproject.com

我想将所有带有 /demo 路径参数的 URL 链接到我在 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 都被链接,而我只希望链接带有 /demo 路径参数的 URL。

我试过了:

  • &lt;data android:host="demoproject.com/demo" /&gt; - 所有 URL 均未链接
  • prefixes: ['https://demoproject.com/demo'] - 所有带有 https://demoproject.com 域的 URL 都已链接

任何想法如何解决这个问题或我在这里做错了什么?

【问题讨论】:

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


    【解决方案1】:

    必须在 IntentFilter 中用pathPrefixpathPattern 定义:

    <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

    【讨论】:

    • android:pathPrefix 搞定了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多