Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack Navigator Goes Back to Previous Screen if Route Matches, Even if Params Are Different on v2 #747

Open
Nicell opened this issue Jul 7, 2023 · 6 comments

Comments

@Nicell
Copy link

Nicell commented Jul 7, 2023

Which package manager are you using? (Yarn is recommended)

yarn

Summary

As of SDK 49 and expo-router v2, when a stack has links pressed on in the following order:

  • /Nick (/[user])
  • /two (/two)
  • /Joe (/[user])

The stack navigator goes back to the /Nick screen when the /Joe link is pressed on the /two page instead of pushing a new screen onto the stack. This behavior does not happen before upgrading. While it does update the params, I was not expecting search params to update for screens, so my app doesn't handle it, and I don't want it to reuse screens. Continually pushing on the stack is better for my app's UX, and I'm not sure if it's achievable with the new update.

Minimal reproducible example

https://github.com/Nicell/stack-test
This repo is built on the tabs@49 template. The 2nd commit is just applied on top of it.

@Nicell Nicell changed the title Stack Navigator Goes Back to Previous Screen if Route Matches, Even if Params Are Different. Stack Navigator Goes Back to Previous Screen if Route Matches, Even if Params Are Different on v2 Jul 7, 2023
@Nicell
Copy link
Author

Nicell commented Jul 7, 2023

I was able to create a workaround by setting the getId prop on the Stack.Screens. See react-navigation/react-navigation#9090

Still not sure why this behavior showed up with SDK 49 specifically.

@EvanBacon
Copy link
Contributor

I wasn't able to reproduce all the screens were pushed as expected, with no popping.

Screenshot 2023-07-07 at 6 28 15 PM

@Nicell
Copy link
Author

Nicell commented Jul 8, 2023

@EvanBacon Here's a video of my minimal reproducible example in the latest Expo Go on an iPhone simulator. All I did was yarn start, open on the simulator, and press each link.

Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-07-07.at.20.37.27.mp4
image

@EvanBacon EvanBacon reopened this Jul 8, 2023
@snowdigital
Copy link

snowdigital commented Jul 26, 2023

for those who facing the same issue use following code

<Stack.Screen getId={({ params }) => params.id} name="user/[id]" />

getID function makes it work

dont forget to spread params

@tr3v3r
Copy link

tr3v3r commented Aug 3, 2023

@snowdigital

Lifesaver!
I can go sleep now :D

@tylerjbainbridge
Copy link

@snowdigital thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants