Reset navigation history to Login screen using react navigation

后端 未结 2 1308
死守一世寂寞
死守一世寂寞 2020-12-11 07:26

I would like after Login (Welcome) the user to navigate to Home. I reset the history so the user cannot go back like this:

const actionToDispatch = Navigatio         


        
2条回答
  •  执念已碎
    2020-12-11 07:42

    For anyone who is looking for React Navigation 3.x and 4.x solution

    import {NavigationActions, StackActions} from 'react-navigation';
    
     const resetAction = StackActions.reset({
          index: 0,
          actions: [NavigationActions.navigate({routeName: 'Home'})],
          key: null,
        });
        this.props.navigation.dispatch(resetAction);
    

    React Navigation move the reset method to StackActions since 3.x

提交回复
热议问题