title: React Native deep linking does not work when app is killed
body: <h1>Possible solution</h1>
  <p>I found a solution myself in the meanwhile, probably not so 'clean'.</p>
  <p>In App.js I specify my initialRouteName like this:</p>
  <pre><code>import {createAppContainer} from 'react-navigation';
  import {createStackNavigator} from 'react-navigation-stack';
  
  import Home from './screens/Home';
  import Form from './screens/Form';
  import {Linking, Platform} from 'react-native';
  import React from 'react';
  
  function getRoute() {
    let route = &quot;&quot;;
    Linking.getInitialURL().then(url =&gt; {
      route = url;
    })
  
    if (route === 'playgroundapp://form') {
      return 'Form';
    } else {
      return &quot;Home&quot;
    }
  }
  
  const AppNavigator = createStackNavigator(
      {
    Home: { screen: Home },
    Form: { screen: Form },
  }, {
        initialRouteName: getRoute()
      });
  
  export default createAppContainer(AppNavigator);
  </code></pre>
  <hr />
  <h1>Question</h1>
  <p>I want to be able to deep link to my React Native application from my iOS widget.<br />
  Linking works fine when the app is running in the background, it navigates to the correct page. But when the app is killed, it only opens the app, but does not navigate to the correct page anymore.</p>
  <p>I followed this tutorial: <a href="https://medium.com/react-native-training/deep-linking-your-react-native-app-d87c39a1ad5e" rel="nofollow noreferrer">https://medium.com/react-native-training/deep-linking-your-react-native-app-d87c39a1ad5e</a></p>
  <p>With a few adjustments from the official documentation: <a href="https://facebook.github.io/react-native/docs/linking" rel="nofollow noreferrer">https://facebook.github.io/react-native/docs/linking</a></p>
  <p>AppDelegate.m</p>
  <pre><code>#import &quot;AppDelegate.h&quot;
  
  #import &lt;React/RCTBridge.h&gt;
  #import &lt;React/RCTBundleURLProvider.h&gt;
  #import &lt;React/RCTRootView.h&gt;
  
  #import &lt;React/RCTLinkingManager.h&gt;
  
  @implementation AppDelegate
  
  - (BOOL)application:(UIApplication *)application
     openURL:(NSURL *)url
     options:(NSDictionary&lt;UIApplicationOpenURLOptionsKey,id&gt; *)options
  {
    return [RCTLinkingManager application:application openURL:url options:options];
  }
  
  - (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
   restorationHandler:(nonnull void (^)(NSArray&lt;id&lt;UIUserActivityRestoring&gt;&gt; * _Nullable))restorationHandler
  {
   return [RCTLinkingManager application:application
                    continueUserActivity:userActivity
                      restorationHandler:restorationHandler];
  }
  
  - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
  {
  #if DEBUG
    return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@&quot;index&quot; fallbackResource:nil];
  #else
    return [[NSBundle mainBundle] URLForResource:@&quot;main&quot; withExtension:@&quot;jsbundle&quot;];
  #endif
  }
  
  @end
  </code></pre>
  <p>App.js</p>
  <pre><code>import {createAppContainer} from 'react-navigation';
  import {createStackNavigator} from 'react-navigation-stack';
  
  import Home from './screens/Home';
  import Form from './screens/Form';
  
  const AppNavigator = createStackNavigator({
    Home: { screen: Home },
    Form: { screen: Form },
  });
  
  export default createAppContainer(AppNavigator);
  </code></pre>
  <p>Home.js</p>
  <pre><code>import React, {Component} from 'react';
  
  import {
    Linking,
    Platform,
    Text,
    View,
  } from 'react-native';
  
  import Form from './Form';
  
  export default class Home extends Component {
    componentDidMount() {
      if (Platform.OS === 'android') {
        Linking.getInitialURL().then(url =&gt; {
          this.navigate(url);
        });
      } else {
        Linking.addEventListener('url', this.handleOpenURL);
      }
    }
  
    componentWillUnmount() {
      Linking.removeEventListener('url', this.handleOpenURL);
    }
  
    handleOpenURL = event =&gt; {
      console.log(event.url)
      this.navigate(event.url);
    };
  
    navigate = url =&gt; {
      const {navigate} = this.props.navigation;
      const route = url.replace(/.*?:\/\//g, '');
  
      const routeName = route.split('/')[0];
      if (routeName === 'form') {
        navigate('Form');
      }
    };
  
    }
  
    render() {
      return (
        &lt;View style={styles.container}&gt;
          &lt;Text style={styles.h1}&gt;Playground&lt;/Text&gt;
        &lt;/View&gt;
      );
    }
  }
  </code></pre>
  <p>So from my widget I link to the app like this:
  <code>extensionContext?.open(URL(string: &quot;playgroundapp://form&quot;)! , completionHandler: nil)</code></p>
  <p>Why doesn't it work when the app is not running in the background? I found a few similar questions, but no answers that worked for me or which were outdated.</p>