I have an issue with resetting Stack Navigator when inside another Stack navigator, here's the scenario:
- User lands on Book List screen
- User navigates to Book Detail screen
- User switches to Settings screen through bottom navigation / tabs
- User switches the account
When user switches the account, I need to clear Books navigation stack, so that navigating back to Books stack through the bottom tab navigation doesn't show a screen/book detail that no longer belongs to the active account.
I suspect this can be achieved using the target
property, I'm just not sure what to feed into it. The documentation says it's the key of the navigator which contains the route (https://reactnavigation.org/docs/navigation-actions/#goback).
this.props.navigation.dispatch({
target: ???, <-- how can I point this to the Books stack?
...CommonActions.reset({
index: 1,
routes: [
{ name: 'book-list' }
]
})
});
However, putting in target: 'books'
, which is the key of the Books tab navigator produces the following error:
The action 'RESET' with payload '{"index":1,"routes":[{"name":"book-list"}]}' was not handled by any navigator. If you are trying to navigate to a screen, check if the screen exists in your navigator.
This is the navigation structure:
NavigationContainer
--Tab.Navigator
----Tab.Screen (Books)
------Stack.Navigator
--------Stack.Screen (Book List)
--------Stack.Screen (Book Detail)
----Tab.Screen (Settings)
------Stack.Navigator
--------Stack.Screen (Settings Page)
Ideally, I would want to reset the Books navigator stack after the user switches the account and don't navigate to Books.