Deep linking is not working when app is closed/killed
See original GitHub issueDescription
If app in background
- specific screen will open as expected. (through deeplink)
If app is not in background or closed
- it will show first screen only. (through deeplink)
I tried some of the work arounds mentioned on stackoverflow but they dont seems to work
References: Deep linking - doesn’t work if app is closed , React Native - Deep linking is not working when app is not in background (Android, iOS), Deep linking not working when app is in background state React native
React Native version:
System: OS: macOS 10.15.7 Binaries: Node: 16.8.0 - /usr/local/bin/node npm: 7.22.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: ^0.64.0 => 0.64.2
Expected Results
It should open the specific screen through deep link when the app is in closed/killed state also.
Snack, code example :
linking.js
const config = {
screens: {
Home:'home',
Profile:'profile,
},
};
const linking = {
prefixes: ['demo://app'],
config,
};
export default linking;
App.js
import React, {useState, useEffect} from 'react';
import {Linking} from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {createStackNavigator} from '@react-navigation/stack';
import {NavigationContainer} from '@react-navigation/native';
import linking from './utils/linking';
import {Home, Profile, SplashScreen} from './components';
const Stack = createStackNavigator();
const App = () => {
function _handleOpenUrl(event) {
console.log('handleOpenUrl', event.url);
}
// this handles the case where a deep link launches the application
Linking.getInitialURL()
.then((url) => {
if (url) {
console.log('launch url', url);
_handleOpenUrl({url});
}
})
.catch((err) => console.error('launch url error', err));
useEffect(() => {
Linking.addEventListener('url', _handleOpenUrl);
return () => {
Linking.removeEventListener('url', _handleOpenUrl);
};
}, []);
return (
<NavigationContainer linking={linking}>
<Stack.Navigator
initialRouteName="SplashScreen"
screenOptions={{...TransitionPresets.SlideFromRightIOS}}>
<Stack.Screen
name="SplashScreen"
component={SplashScreen}
options={{headerShown: false}}
/>
<Stack.Screen
name="Home"
component={Home}
options={{headerShown: false, gestureEnabled: false}}
/>
<Stack.Screen
name="Profile"
component={Profile}
options={{headerShown: false, gestureEnabled: false}}
/>
</Stack.Navigator>
</NavigationContainer>
);
};
export default App;
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:23
Top GitHub Comments
I’m facing the same issue. Any solutions?
same here. Working with react-native 0.65.1 version.