Reset navigation history to Login screen using react navigation

后端 未结 2 1309
死守一世寂寞
死守一世寂寞 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

    0 讨论(0)
  • 2020-12-11 07:45

    I found the solution here: https://github.com/react-community/react-navigation/pull/789.

    const resetAction = NavigationActions.reset({
                index: 0,
                actions: [
                    NavigationActions.navigate({ routeName: 'Welcome' }),
                ],
                key: null
            });
    
    this.props.navigation.dispatch(resetAction);
    

    key: null is the important part.

    0 讨论(0)
提交回复
热议问题