I have implemented deep links for my app with React Navigation V5.
I have a problem regarding Deep Linking. If the app is closed(killed) and it is opened via a deep link it will take me to the home screen rather than the screen it has to take me to.
Here's my linking config, from what I've read in the docs (here), i'm passing the URL from the getInitialUrl function to the subscribe and here
const onReceiveURL = ({ url }) => listener(url);
it should parse the URL to a valid navigation state and take me to the screen it has to. I might be mistaken with how subscribe works, though.
Any help is appreciated, thanks in advance!
const linking = {
prefixes: ['appName://', 'app.appName.com://', APP_WEB_DOMAIN],
async getInitialURL() {
// Check if app was opened from a deep link
const url = await Linking.getInitialURL();
if (url != null) {
return url;
}
},
subscribe(listener) {
const onReceiveURL = ({ url }) => listener(url);
Linking.addEventListener('url', onReceiveURL);
return () => {
// Clean up the event listener
Linking.removeEventListener('url', onReceiveURL);
};
},
config: {
screens: {
SignInScreen: 'login',
UnauthenticatedStack: '',
TrackListScreen: 'playlist/:id/' //:id gets parsed as a string, you have to specify it if you want a number.
}
}
};