Resetting the navigation stack for the home screen (React Navigation and React Native)

前端 未结 13 2384
终归单人心
终归单人心 2020-11-29 23:49

I\'ve got a problem with the navigation of React Navigation and React Native. It is about resetting navigation and returning to the home screen.

I\'ve build a StackN

13条回答
  •  醉梦人生
    2020-11-30 00:02

    This is How I do it :

    reset(){
        return this.props
                   .navigation
                   .dispatch(NavigationActions.reset(
                     {
                        index: 0,
                        actions: [
                          NavigationActions.navigate({ routeName: 'Menu'})
                        ]
                      }));
      }
    

    at least replace 'Menu' with 'Home'. You may also want to adapt this.props.navigation to your implementation.

    In version > 2 follow this:

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

提交回复
热议问题