Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between react-navigation's StackNavigator and SwitchNavigator? [closed]

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?

like image 239
JJT Avatar asked Mar 21 '18 22:03

JJT


People also ask

What is the difference between react navigation and react navigation?

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.

What is the difference between stack Navigator and Tab Navigator?

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.

What is difference between navigate and push in react navigation?

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.

Which navigation is best for React Native?

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.


1 Answers

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

like image 200
Unknown Avatar answered Oct 15 '22 18:10

Unknown