I've created a Snack for this: https://snack.expo.io/HJebCIoiM
The problem is really simple, but most issues I've found on GH and SO are about the opposite behaviour: resetting the StackNavigator to its initial route when switching between items in the DrawerNavigator.
App structure
- Drawer
- Router
- First screen
- Second screen
- Other screen
- Router
The initial route is Router, which by default shows the first screen.
Current behaviour
- I go from the first screen to the second screen
- I toggle the drawer
- I go to the other screen in the drawer
- I go back to the Router
- It shows the first screen
Expected behaviour:
In step 5. it should show the second screen, because that's the last route I was on when I toggled the DrawerNavigator.
I don't understand why it doesn't preserve the state of the stack, and just takes me back to the screen I was on before, but instead resets the stack to its initial route.
What confuses me even more is that many people are reporting that this is the default behaviour of their app, but they do want to reset the stack and are struggling with this:
- Resetting the navigation stack for the home screen (React Navigation and React Native)
- Clear stack being navigated to React-Navigation
- How to reset the state of a StackNavigator nested in a DrawerNavigatior?
I don't understand why it does reset it all the time in my case. (and as you should be able to reproduce with the Snack I posted above.