Disable back button in react navigation

前端 未结 18 1756
长发绾君心
长发绾君心 2020-12-12 18:31

I\'m using react native navigation (react-navigation) StackNavigator. it starts from the Login page throughout the whole lifecycle of the app. I don\'t want to have a back

18条回答
  •  星月不相逢
    2020-12-12 19:21

    The SwitchNavigator would be the way to accomplish this. SwitchNavigator resets the default routes and unmounts the authentication screen when the navigate action is invoked.

    import { createSwitchNavigator, createStackNavigator, createAppContainer } from 'react-navigation';
    
    // Implementation of HomeScreen, OtherScreen, SignInScreen, AuthLoadingScreen
    // goes here.
    
    const AppStack = createStackNavigator({ Home: HomeScreen, Other: OtherScreen });
    const AuthStack = createStackNavigator({ SignIn: SignInScreen });
    
    export default createAppContainer(createSwitchNavigator(
      {
        AuthLoading: AuthLoadingScreen,
        App: AppStack,
        Auth: AuthStack,
      },
      {
        initialRouteName: 'AuthLoading',
      }
    ));
    

    After the user goes to the SignInScreen and enters their credentials, you would then call

    this.props.navigation.navigate('App');
    

提交回复
热议问题