微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Android 上使用带有路径参数的 React Navigation 通用链接?

如何解决如何在 Android 上使用带有路径参数的 React Navigation 通用链接?

我有以下域: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 中用 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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。