Hello!
I’m having a problem with deep links on Android.
When building my application, deep link does not navigate to the defined screen. Just open the app.
I can open my app using npx uri-scheme open "navigation://screen" --android
in the simulator and using "navigation://screen"
in a device. And navigates to the “screen” Screen.
But using the link https://my-site.com/screen
, only open my app but does not navigate o the “screen” Screen.
Can you help me? Thanks
- SDK Version: 46
- Platforms: Android/iOS
app.json
...
"scheme": "navigation",
"intentFilters": [
{
"action": "VIEW",
"data": [
{
"scheme": "https",
"host": "my-site.com"
}
],
"category": [
"BROWSABLE",
"DEFAULT"
]
}
]
App.tsx
....
<NavigationContainer
linking={LinkingConfiguration}
<RootNavigator />
</NavigationContainer>
RootNavigator
<Stack.Navigator>
<Stack.Screen name="Root" component={BottomTabNavigator} options={{ headerShown: false }} />
<Stack.Screen name="NotFound" component={NotFoundScreen} options={{ title: 'Oops!' }} />
<Stack.Screen name="Screen" component={Screen} options={{ title: 'Screen!' }} />
<Stack.Group screenOptions={{ presentation: 'modal' }}>
<Stack.Screen name="Modal" component={ModalScreen} />
</Stack.Group>
</Stack.Navigator>
LinkingConfiguration
...
prefixes: [Linking.createURL('/'), "navigation://, https://my-site.com"],
config: {
screens: {
Root: {
screens: {
TabOne: {
screens: {
TabOneScreen: 'one',
},
},
TabTwo: {
screens: {
TabTwoScreen: 'two',
},
},
},
},
Screen: 'screen',
Modal: 'modal',
NotFound: '*',
},
},
async getInitialURL() {
const url = Linking.getInitialURL()
if (url != null) {
return url
}
},
subscribe(listener) {
const onReceiveURL = ({ url }: { url: string }) => {
listener(url)
}
// Listen to incoming links from deep linking
const subscription = Linking.addEventListener("url", onReceiveURL)
return () => subscription.remove();
}