question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Navigating back to a previous navigator?

See original GitHub issue

I’m using react native with the following versions:

"navigation": "5.4.1",
"navigation-react": "4.2.0",
"navigation-react-native": "7.4.2",

I’ve been following the docs and I’ve added a TabBar. I’m using the same configuration as here: https://grahammendick.github.io/navigation/documentation/native/tab-bar.html

So I have a root stateNavigator that contains the tab scene as well as a login page and the tab scene contains two tabs ‘home’ and ‘profile’. So my question is how do I allow the user to log out from the profile tab and navigate back to the login page in the root navigator?

So basically my App.tsx file contains this navigator:

const stateNavigator = new StateNavigator<RootNavigator>([
    { key: 'tabs' },
    { key: 'login' },
  ]);

const { tabs, login } = stateNavigator.states;
tabs.renderScene = () => <Tabs />;
login.renderScene = () => <Login />;
stateNavigator.navigate('login');

const App: React.FC = () => (
  <NavigationHandler stateNavigator={stateNavigator}>
    <NavigationStackIOS />
  </NavigationHandler>
);

and my Tabs component contains the following:

// Home tab navigator
const homeNavigator = new StateNavigator<HomeTabNavigation>([
  { key: 'home', trackCrumbTrail: true },
]);
const { home } = homeNavigator.states;
home.renderScene = () => <Home />;
homeNavigator.navigate('home');

// Profile tab navigator
const profileNavigator = new StateNavigator<ProfileTabNavigation>([
  { key: 'profile', trackCrumbTrail: true },
]);
const { profile } = profileNavigator.states;
profile.renderScene = () => <Profile />;
profileNavigator.navigate('profile');

const Tabs: React.FC = () => (
  <>
    <NavigationBar hidden />
    <TabBar
      primary
      bottomTabs
      barTintColor="#FFFFFF"
      selectedTintColor="#EC418E"
      unselectedTintColor="#B5B5B5"
    >
      <TabBarItem title="Home">
        <NavigationHandler stateNavigator={homeNavigator}>
          <NavigationStack />
        </NavigationHandler>
      </TabBarItem>
      <TabBarItem title="Profile">
        <NavigationHandler stateNavigator={profileNavigator}>
          <NavigationStack />
        </NavigationHandler>
      </TabBarItem>
    </TabBar>
  </>
);

Do I need to structure this in some other way or is there some way for me to navigate back from the profile tab to the login screen?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
grahammendickcommented, May 13, 2021

I’m really glad you like the Navigation router and I’m happy I could help you out

1reaction
hlynurstefcommented, May 13, 2021

@grahammendick I was already using the unmountStyle prop to create an iOS like animation on Android but I didn’t realise I could pass in an empty string to disable the animation, now I know 👌

Awesome library btw, I’m really enjoying using it.

Since you’ve answered all my questions I’m going to close this issue 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-navigation go Back not navigate to previous screen
I have welcome (login and register) screen and then Main stack. main stack include all screens after success auth(login\register). MainStack = ...
Read more >
Navigate to a new screen and back - Flutter documentation
1. Create two routes; 2. Navigate to the second route using Navigator.push(); 3. Return to the first route using Navigator.pop(); Interactive example.
Read more >
How to go back to another stack navigator? goBack / pop ...
PROBLEM: from Dashboard Landing screen, if I do navigation.navigate('AccountDetails'); it takes me to AccountDetails ,. but while going BACK ...
Read more >
Refresh Previous Screen after Going Back in React Navigation
Introduction. This is an Example to Refresh the Previous Screen after Going Back to the old Screen in React Native using React Navigation....
Read more >
React Navigation re-render / reset previous page's state on ...
While using react-navigation, the screens do not re-render or refresh. So, when user logsout and comes back to login screen, the values are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found