Here is my project file hierarchy
RootTabNavigator
| AuthStackNavigator // I want to go back to this navigator
| AuthoScreen
| Welcome Scre
You can define custom navigation logic by extending the router. To accomplish what you want that you described in the project file hierarchy in your question you can do something like this below.
MainTabNavigator.js
...
RootTabNavigator.router.getStateForAction = (action, state) => {
if (state && action.type === 'GoToAuthScreen') {
return {
...state,
index: 0,
};
}
return RootTabNavigator.router.getStateForAction(action, state);
};
MainTabNavigator.router.getStateForAction = (action, state) => {
if (state && action.type === 'GoToAuthScreen') {
return {
...state,
index: 0,
};
}
return MainTabNavigator.router.getStateForAction(action, state);
};
MenuStackNavigator.router.getStateForAction = (action, state) => {
if (state && action.type === 'GoToAuthScreen') {
return {
...state,
index: 0,
};
}
return MenuStackNavigator.router.getStateForAction(action, state);
};
In the Menuo Screen file
componentWillReceiveProps(nextProps) {
if ( nextProps.token == undefined || _.isNil(nextProps.token) ) {
const goToAuthScreen = () => ({
type: 'GoToAuthScreen',
});
nextProps.navigation.dispatch(goToAuthScreen);
...
}
}