Title: How to skip nested navigator's initial route?
Tags: react-native;react-navigation
Question: I have a navigation like so: 

```Loading: SwitchNavigator {
  Auth: Stacknavigator,
  Main: StackNavigator,
  Onboard: StackNavigator,
}
```

every one of ```StackNavigator```s has an initial route set. Under certain circumstances, I want to go from ```loading``` navigator to a specific route on ```onboard``` navigator. If I use just ```navigator.navigate('DesiredRoute')```, it squeezes in also onboard's ```initialRoute```, so the navstack looks like ```[InitialRoute, DesiredRoute]``` instead of ```[DesiredRoute]```. How to get rid of the ```InitialRoute```?

Code example: 

```// Loading.js

if (loadingComplete) {
  if (!user) {
    navigation.navigate('auth')
    return
  }
  if (user &amp;&amp; userData) {
    navigation.navigate('Main')
    return
  }  
  if (onboardingCheckpointCleared) {
    // this creates `['InitialRoute', 'DesiredRoute']` instead of `['DesiredRoute']`
    navigation.navigate('DesiredRoute')
    return
  }
  navigation.navigate('Onboard')
}
```

Comment: I haven't tested myself with all the latest packages, but supposing that what you wrote is correct, how is this a problem? What are you trying to do? This does look a lot like a issue that could be solved elsewhere


Here is another answer: I assume you are navigating to ```DesiredRoute``` from outside the ```Onboard``` stack navigator

If you're outside the ```Onboard``` navigator, doing ```navigation.navigate('DesiredRoute')``` will trigger two actions: first, it will navigate to the ```Onboard``` stack navigator (so it will also activate the default sub screen of it ```InitialRoute``` like you call it) and then it will push the ```DesiredRoute```. If you want to go to ```Onboard``` with only ```DesiredRoute``` on the stack, you can use the sub actions of the navigation actions like this:

```navigation.navigate('Onboard', undefined, StackActions.replace('DesiredRoute'));
```

The third argument is an action that can be will be executed by the first argument navigator (if the first argument is not a screen but a navigator). Here it will navigate to the ```Onboard``` navigator and thus put the ```InitialRoute``` in the stack (automatically as it's the initialRoute of ```Onboard```). However, the ```StackAction.replace('DesiredRoute')``` will be executed by the ```Onboard``` navigator and will replace ```InitialRoute``` with ```DesiredRoute```.

See the official doc about the navigate: https://reactnavigation.org/docs/en/navigation-prop.html#navigate-link-to-other-screens


Here is another answer: I ended up creating a custom router that strips out the initial route when navigating to my nested stack:

```const MyStackNav = createStackNavigator({ ...routes })

const defaultGetStateForAction = MyStackNav.router.getStateForAction
const customGetStateForAction = (action, state) =&gt; {
  const defaultNavState = defaultGetStateForAction(action, state)

  // If we're pushing onto a stack that only has a defaulted initialRoute
  if (
    !!defaultNavState &amp;&amp;
    !defaultNavState.routeName &amp;&amp; 
    defaultNavState.isTransitioning &amp;&amp;
    defaultNavState.index === 1 &amp;&amp;
    action.type === NavigationActions.NAVIGATE
  ) {
    const newState = {
      ...defaultNavState,
      index: 0, // Decrement index
      routes: defaultNavState.routes.slice(1), // Remove initial route
    }
    return newState
  }
  return defaultNavState
}
```


Here is another answer: This is expected behavior, if you want only ```DesiredRoute``` to appear then you have to set that route in ```Loading``` as well like below,

```Loading: SwitchNavigator {
  Auth: Stacknavigator,
  Main: StackNavigator,
  Onboard: StackNavigator,
  DesiredRoute: ScreenName
}
```

Writing like this will not create any clash, you are safe to write.

Comment for this answer: @Zygro do you have any concerns with this answer or any other requirements?

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:08/19/19', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<react-native><react-navigation>', 'Title': "How to skip nested navigator's initial route?", 'ViewCount': 1048, 'id': 57556984, 'user_AboutMe': None, 'user_AccountId': 5702906.0, 'user_DisplayName': 'Zygro', 'user_Reputation': 6489.0, 'user_Views': 191.0, 'user_id': 4507367.0}}