As of this writing, the Docs don't provide a description of SwitchNavigator
's purpose.
I've tried using both StackNavigator
and SwitchNavigator
interchangeably and I personally cannot spot a difference. Although I'm certain there is.
Can anyone explain what the added benefit of SwitchNavigator
is over StackNavigator
? Or a scenario where one might use it over the other?
TL;DR: React Navigation has a declarative API with built-in hooks, while React Native Navigation has imperative APIs with a community library for Hooks. React has changed how we think about interface development.
StackNavigator: When user taps a link, a new screen is put on top of old screens. TabNavigator: User navigates to different screens by tapping on tabs along the top or bottom of the screen.
push : pushes a new instance of the screen even if it already exists in the current stack. navigate : if the component with its name exists in the current stack, then it goes to that screen. If not, it creates a new instance of the screen and pushes it onto the stack.
react-native-navigation: uses the underlying native APIs on iOS and Android, similar to createNativeStackNavigator. This is a popular alternative to React Navigation and may be a better fit for you if you are trying to integrate React Native into an existing large native app.
Here is a description from React Navigation:
The purpose of SwitchNavigator is to only ever show one screen at a time. By default, it does not handle back actions and it resets routes to their default state when you switch away. This is the exact behavior that we want from the authentication flow: when users sign in, we want to throw away the state of the authentication flow and unmount all of the screens, and when we press the hardware back button we expect to not be able to go back to the authentication flow. We switch between routes in the SwitchNavigator by using the navigate action.
Source: https://reactnavigation.org/docs/auth-flow.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With