Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling initial state of a destination StackNavigator from initial SwitchNavigator screen

I have a SwitchNavigator 'switch'. It's initial state 'root' is a screen component that is just loading state and determining the correct initial route (A, or B) of a StackNavigator 'stack'.

--switch
     --root
     --stack
        -A
        -B

what's the right way for the 'root' component to tell the Switch Navigator to switch to 'stack' and then start with either 'A or B' conditionally?

like image 220
nwales Avatar asked Dec 04 '25 08:12

nwales


1 Answers

In the root component, when your job is done, just call navigation.navigate like this:

this.props.navigation.navigate(condition ? 'A' : 'B');
like image 187
Sadegh Teimori Avatar answered Dec 07 '25 03:12

Sadegh Teimori



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!