20

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?

JJT
  • 407
  • 5
  • 12
  • 3
    "Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. " Could somebody tell me how could this question get any more specific? Unless the user has authored the library and knows more about it, I think this question is specific enough. – ZenVentzi Aug 02 '19 at 19:22

1 Answers1

29

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

Unknown
  • 601
  • 7
  • 17
  • 1
    Thanks for finding that. They should add this definition to the main SwitchNavigator documentation. – JJT Apr 02 '18 at 14:15
  • 2
    Thanks for your answer, it helps me as well :) I've opened a Pull Request to add it to the doc : https://github.com/react-navigation/react-navigation.github.io/pull/149 – Aurore Malherbes May 01 '18 at 10:55