Open twelve17 opened 4 years ago
Same here, could not achieve this common use case. I was able to achieve this in previous version (v3 or v4)
This is a much later reply, so not likely useful for the original authors/commenters of this issue, but perhaps useful for anyone coming later:
I described a way that I was able to create a reset()
call that allowed me to jump between navigators successfully in a discussion thread. The navigation state argument's structure when working with nested navigators isn't as simple as it may seem.
In case it helps anyone, you can check out my comment on that discussion.
Note: I asked on the #react-navigation discord channel, but was unable to get any leads. So I am hoping I can try here, per the Navigation prop reference documentation:
Given a fairly common navigation structure:
I am trying to navigate from
ScreenB
toScreenD
, with the caveat that since this involves switching tabs, I wish to haveStackNavB
consist ofScreenC
andScreenD
when the navigation is complete, asScreenC
is theinitialScreen
of that stack navigator. This way the user can hit the back button and get toScreenC
, otherwise it will not be accessible.Current Behavior
Using
reset
does not seem to perform any navigation changes at all. I also tried usingnavigate(<navigator>, { screen: <screen> }
, but this navigates to the other stack navigator and does not include the initial screen, making it no longer accessible (as there is no back button present).Expected Behavior
When tapping on "Edit Profile" from the
HomeTab
, the user is navigated to theAccountTab
'sEditProfile
screen (which is not the initial screen), and resetting theAccountTabStack
to contain both theAccount
andEditProfile
routes.How to reproduce
I have a snack here to demonstrate an app with such a navigation structure: https://snack.expo.io/@alexwb/686a2a
The screen names are different, but essentially, tapping on "Edit Profile" from the
HomeTab
would take the user to theAccountTab
, with that tab's stack navigator having both the initial screen (Account
) plus the screen being explicitly navigated to (EditProfile
).On the
HomeTab
, try tapping on either of theGo to Edit Profile
links (each tries a different approach to do this, using different react navigation APIs. Neither one seems to accomplish the goal.Note that I was not able to use the very latest versions of the dependencies, as they would fail on expo with the error described in this issue: https://github.com/react-navigation/react-navigation/issues/7978
Your Environment