onPress={() => {
const resetAction = StackActions.reset({
index: 0,
key: "Tab1",
actions: [navigation.navigate({ routeName: "Tab1" })]
});
navigation.dispatch(resetAction);
}}
I want to navigate to Tab1 from 2nd screen of my stack navigator by resetting the stack. I am not using Redux for this. In a current way, I am either able to reset the stack or move to the Tab1 page(it is being added as a separate screen on the stack). I would like to do reset the stack first and then move on to the Tab1 screen. Is there any way we can achieve this?
This is my success example
The code will open two screens and judge which screen to display in front based on index
, index
0 : display the first one, index
1 : display the second one (the tab1
screen will be displayed here)
Hopefully it helped you
import { NavigationActions } from 'react-navigation';
const resetAction = NavigationActions.reset({
index: 1,
actions: [
NavigationActions.navigate({ routeName: 'home' }),
NavigationActions.navigate({ routeName: 'Tab1' })
]
})
this.props.navigation.dispatch(resetAction);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.