简体   繁体   中英

React native navigation showing both stacks while condition is used

I have two stack navigators for my app. Only one should show up, based of the isLoggedIn condition. However, both show when isLoggedIn = true . But when I set the condition to false , it only shows app. I simply dont get it.

export default function App() {
 const isLoggedIn = true;
 return (
  <NavigationContainer>
      <Stack.Navigator>
          {isLoggedIn === true ? (
          <Stack.Screen name="Auth" component={AuthStackNavigator} />
          ) : (
          <Stack.Screen name="App" component={AppBottomTabNavigator} />
          )}
      </Stack.Navigator>
  </NavigationContainer>
);
}

When isLoggedIn is set to true

When isLoggedIn is set to false

Could you try this.

export default function App() {
 const isLoggedIn = true;
 return (
  <NavigationContainer>
      <Stack.Navigator>
          {isLoggedIn === true  && <Stack.Screen name="Auth" component={AuthStackNavigator} />}
         {isLoggedIn === false && <Stack.Screen name="App" component={AppBottomTabNavigator} />}
      </Stack.Navigator>
  </NavigationContainer>
);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM