I have the following route structure:
StackNavigator
-StackNavigator
-TabNavigator
--Tab1
---Route 1 (Stack) (initial)
---Route 2 (Stack)
--Tab2
---Route 3 (Stack) (initial)
---Route 4 (Stack)
When I visit Tab1 -> Route 1 -> Route 2 -> Tab2
and go back to Tab1
, the active route is 2 instead of the initialRoute
1.
I'm doing the following:
tabBarOnPress: ({ scene }) => {
const { route } = scene;
const tabRoute = route.routeName;
const { routeName } = route.routes[0];
navigation.dispatch(NavigationActions.navigate({ routeName: tabRoute }));
navigation.dispatch(NavigationActions.reset({
index: 0,
actions: [
NavigationActions.navigate({ routeName }),
],
}));
},
but the problem is that it first shows Route 2
and then navigate to Route 1
.
How can I reset the previous tab/screens, so when I switch the tab always to show directly the initial route.