Andry
Andry

Reputation: 367

How to use React Navigation universal links with path parameters on Android?

I have the following domain: https://demoproject.com

I would like to link all URL-s with /demo path parameter with my React Native application on Android so that for example URL https://demoproject.com/demo?a=1&b=2 will be linked, but any other URL with same domain, but different path parameters will be excluded.

Right now I am using React Navigation 5 like this:

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>

Linking itself is working fine, but the problem is that all URL-s with prefix https://demoproject.com are being linked while I only want URL-s with /demo path parameter to be linked.

I have tried:

Any ideas how to solve this or what am I doing wrong here?

Upvotes: 0

Views: 1006

Answers (1)

Simon Marquis
Simon Marquis

Reputation: 7516

It must be defined in the IntentFilter with pathPrefix or 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>

Source: https://developer.android.com/guide/topics/manifest/data-element#path

Upvotes: 1

Related Questions