0

I faced the problem during developing application in React-Native js framework with navigation. I, ve got a StackNavigator, which navigates me between Login and Main pages. But I don't want to make user navigate back to login page, when he either hits phone button, or navigates by button on the bar of screen, without logging out

Is there a way to deny StackNavigator to navigate back to Login page?

kboskin
  • 422
  • 3
  • 12

1 Answers1

2

If I've understood correctly, once you've ascertained the login is successful, what you need to do is reset the stack via a Reset Navigation Action.

import { NavigationActions } from 'react-navigation'

const resetAction = NavigationActions.reset({
  index: 0,
  actions: [
    NavigationActions.navigate({ routeName: 'Profile'})
  ]
})

this.props.navigation.dispatch(resetAction)

with the name of your route, which is I presume is Home or something along those lines.

If you wanted to go back in a log-out state by resetting the whole thing you would have to pass null to the key param.

Nelloverflow
  • 1,511
  • 1
  • 11
  • 15