1

I have a Login Page(StackNavigator) and a Tabbed pages(TabNavigator).

export const Root = StackNavigator({
  LoginScreen: {screen: Login},
  Tabs: {screen: Tabs}
},
  {
  initialRouteName: 'LoginScreen'
  }
)

After logging the user in there is still a possibility for the user to go back(to Login Page) by swiping back. What is the way of popping the login route from the Route Stack or disabling the back swipe option. Thanks

Nikasv
  • 1,317
  • 5
  • 17
  • 33

2 Answers2

2

Dispatch a reset action instead of the normal navigation dispatch. That way you can set the stack to the state you want it to be after logging in and remove your LoginScreen from the stack.

Example related answers:

Michael Cheng
  • 9,644
  • 6
  • 46
  • 48
0

The official way to handle it from React Navigation (v6) is to define the screens in the navigator based on an isSignedIn condition so that the Login screen will not exist within the navigator once the isSignedIn variable has been set to true.

For example:

<Stack.Navigator>
  {isSignedIn ? (
    <Stack.Screen name="Tabs" component={TabsScreen} />
  ) : (
    <Stack.Screen name="Login" component={LoginScreen} />
  )}
</Stack.Navigator>

See the Authentication Flows section for more information.

Ian
  • 1,746
  • 1
  • 15
  • 28