question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deep linking is not working when app is closed/killed

See original GitHub issue

Description

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:open
  • Created 2 years ago
  • Reactions:8
  • Comments:23

github_iconTop GitHub Comments

11reactions
jinghongchancommented, Nov 2, 2021

I’m facing the same issue. Any solutions?

7reactions
kale1dcommented, Nov 12, 2021

same here. Working with react-native 0.65.1 version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deep linking is not working when app is not in background ...
I think .onLink.listen() function only get hit when app is resumed from background. If you want your deeplink work when app have a...
Read more >
React Native : Deep linking is not working when app is closed ...
In React Native, IOS and android deep linking is not working when app is closed. I have resolved this issue in my app....
Read more >
Why doesn't your deeplink/redirection work when your app is ...
This case happens as your mainActivity (homepage) overrides the action preventing the redirection from running properly. In order to solve have a compliant...
Read more >
Universal links not working when attached in a push ...
I'm experiencing a problem in ios when the app is closed (killed) and a notification with a deep link is received: the url...
Read more >
Testing openURL to cold started app | Apple Developer Forums
I have an issue when opening the app from a URL (deep link) when the app is not in device memory and is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found