Skip to content

Sub-navigator renders first screen in a stack #6995

@skovhus

Description

@skovhus

Current Behavior

Current behavior: when opening a screen inside a sub stack navigator it always renders the first screen or the screen specified as initialRouteName. That makes sense for a top-level navigator, but it makes some things rather difficult for sub navigators.

Code example is here: https://snack.expo.io/H1Mgdt3MS

I have 3 screens:

  • MainScreen
  • ScreenA (modal)
  • ScreenB (modal on the same level as ScreenA)

I don't want react-navigation to render any routes inside the modal stack unless I tell it to. Two reasons for this:

  1. the screens inside the sub stack navigator requires params in order to work
  2. I don't want a history entry in my app for the first screen (see the second gif below, where the back button should go to MainScreen)

xxx

xxx2

Expected Behavior

There would be a way to bypass rendering the first screen in a child stack navigator. Setting initialRouteName to null would be logical to me.

How to reproduce

https://snack.expo.io/H1Mgdt3MS

Your Environment

software version
react-navigation 3.11.1
react-native 0.59.10
node node 10, 11 and 12
npm or yarn yarn

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions