I build an app with react-native, expo and react-navigation. I have a main drawer navigator who has in it 2 other stack navigator. One stack navigator have 2 pages; Products
and Product. When I click on one product in the Products
page, it goes into the Product
page. Ben if I click on another link in my drawer navigator, I would like that the Products page's stack navigator would return to it's initialRoute when leaving the stack navigator.
I tried to set the initialState for when I exit the stack navigator, it render the initialState when I click on the navigator link in my drawer navigator, but it doesn't work when I'm in the child page and exit the navigator. When I click again on Products
in my drawer, instead of navigate to the Products
page, it stayed on Product
.
I can create statics links in my drawer navigator and use this.props.navigation.navigate
to always go to this.props.navigation.navigate('Products')
, but it will be the last thing I want. I would really love that my drawer navigator stays dynamic with what I pass to it.
I tried to this.props.navigation.navigate
when the componentWillUnmount
lifecycle goes on, but it didn't work.
How can I do this?
Thank you for your help!