0

Is there a way to access a root stack navigator from an inner stack navigator? For example:

const Root = StackNavigator(
{
  Login: {
      screen: Login,
    },
    TabNav: {
      screen: TabNav    
    }
}
);

const TabNav = TabNavigator(
  {
    Content: {
      screen: Content,
    },
    Settings: {
      screen: SettingsStack
    }
  }
);

Within that SettingsStack screen I have a logout button. How would I access the Root Stack to navigate back to Login? Rather than that inner stack in the Tab Navigation just pushing to the login page within the child stack.

5
  • 1
    @bob from TabNav in StackNavigator pass a function as a screenProp to TabNavigator . Now whenever you want to logout call that function Commented Oct 6, 2017 at 9:30
  • Would I need to pass the props into SettingsStack similarly? Commented Oct 6, 2017 at 18:30
  • I suppose you would have to do so . Cauz SettingsStack is a Navigator inside another navigator Commented Oct 8, 2017 at 11:05
  • Awesome, it worked. Thanks! Commented Oct 10, 2017 at 23:14
  • Posting it as an answer for others to benefit . Commented Oct 11, 2017 at 6:04

1 Answer 1

3

From TabNav in StackNavigator pass a function as a screenProp to TabNavigator . Use the function whenever you want to logout. Since SettingsStack is a navigator inside another navigator pass the props into SettingsStack to make it work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.