I'm trying to route from one StackNavigator to another, both of which are inside a TabNavigator. I'm currently able to get there by simply doing:
this.props.navigation.navigate('Screen3')
But I also want to reset that tab when I go to it. Here is how my app navigators are generally set up:
- Main (StackNavigator) - LoginScreen - MainTabs (TabNavigator) - Tab1 (StackNavigator) - Screen1 - Screen2 - Tab2 (StackNavigator) - Screen3 - Screen4
How could I navigate to Screen3
but also reset the StackNavigator Tab2
?
I've also tried doing this, to no avail:
let resetAction = NavigationActions.reset({ index: 0, key: 'Tab2', actions: [ NavigationActions.navigate({ routeName: 'Screen3' }) ], }); this.props.navigation.dispatch(resetAction);
To reset the navigation stack for the home screen with React Navigation and React Native, we can use the navigation. dispatch and the CommonActions. reset methods. import { CommonActions } from "@react-navigation/native"; navigation.
first time screen init TabA ,user click TabB >> TabB has button click to PageA >> PageB >> PageC ,PageC has a button to reset to Tab. let resetAction = NavigationActions. reset({ index: 0, actions: [ NavigationActions. init({routeName: 'Tab'}), ] }); this.
Since you have multiple screens in common and some different data (title, description, etc), you can create only one common stack navigator with multiple screens, and then you can call it from anywhere else.
The replace action allows to replace a route in the navigation state. It takes the following arguments: name - string - A destination name of the route that has been registered somewhere. params - object - Params to pass to the destination route.
You'll have to dispatch two navigation actions, one to reset the stack of the current tab and another to navigate to the next screen:
let resetAction = StackActions.reset({ index: 0, actions: [ NavigationActions.navigate({ routeName: 'Screen1' }) ], }); this.props.navigation.dispatch(resetAction); this.props.navigation.navigate('Screen3');
Here is a snack
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With