The react-navigation v5 has converted its usability to Component base, and there is no such a kind of SwitchNavigator feature available.
We can use the react-navigation v5 as a component rendering to declare our screens and create our navigators.
As we are able to use the conditions in component rendering so we can put the condition in navigator rendering to check whether a user is logged in or not, if yes then show the MainApp navigation otherwise show AuthNavigation.
For Ex.
isSignedIn ? (
<>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Profile" component={ProfileScreen} />
<Stack.Screen name="Settings" component={SettingsScreen} />
</>
) : (
<>
<Stack.Screen name="SignIn" component={SignInScreen} />
<Stack.Screen name="SignUp" component={SignUpScreen} />
</>
)
For more information check-out the official doc:
https://reactnavigation.org/docs/auth-flow
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…