Home > OS >  How to ignore React Navigation state persistence for a nested stack?
How to ignore React Navigation state persistence for a nested stack?

Time:11-05

I've a nested tab navigation with React Navigation and I use AsyncStorage for state persistence of the navigation. What I want to do is ignoring the saving of the state when user opens the nested navigation stack (Programs > ProgramMain/Recipes/Support). Here is my structure:

-Home
-Programs
---ProgramMain
---Recipes
---Support
-Profile

I tried to inspect passed state variable of the NavigationContainer's onStateChange but couldn't figure out how can I know which screen/stack is selected.

Thank you very much for your help.

CodePudding user response:

I think you're on the right path and you can find this info in the route property of the state variable passed by NavigationContainer's onStateChange:

Every state object contains a route property (list of route objects), which lists the screens that are rendered in the navigator.

A route object may also contain a state: An optional object containing the navigation state of a child navigator nested inside this screen.

See https://reactnavigation.org/docs/navigation-state

This page shows an example on how to get the active route from a navigator so you know which screen is currently active.

  • Related