Reset navigation history to Login screen using react navigation

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

提交回复
热议问题