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
Cannot navigate to same route with different params #2882
Comments
Currently, the library does not support idempotent actions (you can navigate to the same screen over and over) but it is part of the new roadmap. #2585. Until this exists in the lib, you'll need to hand-roll a solution. (closing to reduce redundancy on the subject) |
Sorry (it's a messy topic), I misunderstood your issue. It was actually patched, then reverse, so, at the moment, as far as I can tell, you should be able to push twice the same rote in a Stack. Can you provide a repo / expo snack that has the behaviour you are experiencing? It's kinda weird that you are not able to do it atm. |
@kelset yes, I am getting a lot of mixed messages. I saw quite a few issues where people can continuously navigate to the same screen. And a lot of them did not want it because it can apparently happen accidentally. I have not had that though but I would like to be able to navigate to the same screen but with different params. At the moment no new screen is pushed and the current one just gets the new params in-place. I think this is what I a lot of other people wanted. As I said I am on 1.0.0-beta.15 and I was on 1.0.0-beta.11 where it did not work either. I am not sure on what version I need to be so that the idempotent fix was either never there or has been reversed. I cannot use 1.0.0-beta.16 at the moment though because it is broken as can be seen by some recent issues. |
Ok so I made a basic demo repo but it did not have the problem. After a lot of tweaking, I finally found that this only happens in the big app because the routeName I was using was for a screen inside a TabNavigator and obviously the TabNavigator doesn't push to the stack (facepalm). |
It's a bit late, but come into this issue only now and searching on Google landed here. I've resolved using a "fake" screen that dispatch the navigation, so the stack is filled with different route key:
Navigate to this route with this:
hope this helps. |
https://reactnavigation.org/docs/en/navigation-key.html#usage-with-the-navigate-navigation-actionshtml-navigate-call
or
|
@marvincreat thank. Using |
@marvincreat i didn't get that |
you should just add key to your navigation props like this : this.props.navigation.navigate ({ key: Math.random () * 10000, routeName: routeName, params: params }) it work for me, hope help you |
@ltsharma It's just a unique ID that is generated to help the stack differentiate between screens with the same routeName. I'm using something like this -
|
the answer from @sagunkho makes the most sense here - you most likely have some data associated with the screen (an id, at category name, whatever). if you don’t, then there is some static difference and you can statically give it a different route key. if that somehow isn’t true, just use push instead of navigate. push will generate a unique key for you, no need to generate one randomly manually. |
@marvincreat how do you use navigation.goBack() |
@marvincreat Thanks for that tip, saved me a lot of hassle 👍 |
None of this seems to work for me.
|
@rochapablo Maybe it doesn't work in v2 |
For those that face the same issue in v2, @sagunkho solution worked. this.props.navigation.navigate({
routeName: MyScreenName,
key: `${MyScreenName}-step${this.params.step + 1}`,
}) |
When i use this.props.navigation.navigate({ routeName:"A", params:{id: 1}, key:uuid.v4() }); |
@xiamencloud I had the same issue - seems in my case I was using numbers for the key instead of a string and changing to a string seemed to solve it. I imagine uuid.v4() returns a string though so not sure in your case. |
Any other suggestions? I am having this same issue in "react-navigation": "^3.0.9" |
I tryed tu use:
but I get
Edit: It was caused by using randm number as key. |
I have the same problem. Pushing to the same screen with different params does not push the same screen onto the stack, and so I don't get the screen slide animation nor can I go back to the previous same screen that has the different params. I am using |
In From the docs <Button
title="Go to Details... again"
onPress={() => this.props.navigation.push('Details')}
/>
https://reactnavigation.org/docs/en/navigating.html#navigate-to-a-route-multiple-times |
@kirkdrichardson omg thank you!! It's cleaner and makes so much more sense now! |
@sungsong88 Yeah, it really depends on your setup. The Here is where it gets tricky. If I On the other hand, if my route history is [A, B, C], and I In our case, this was important because we had Profile component that took an id in params. Without using Hopefully that didn't make it more confusing 😆 |
I fixe this by navigating to my screen like this : @onAction(){
} ....And in my component "myScreen" , i handle params changes inside componentDidUpdate() method. Hope this helped |
For those trying to deeplink into their app with a URI scheme, while the app is already at the desired path, (e.g.
|
i think all approaches dont work with DrawerNavigator. Anyone could confirm? I'm getting crazy... |
Is not working for Drawer Navigator. I have this:
If I press the first button I get "test". If I press the second button I still get "test". |
@sanchitos for the first button change it to:
For the second button, use:
|
thanks man.. for your solution.. perfect!! |
this.props.navigation.replace({....}) instead of navigate worked for me |
Hi @kirkdrichardson , I am using pusing the same screen, anyway after new screen take inplace I need to call a http request to update new data depend on user's pressing.
The problem is after press back from screen2, the screen1 show user2 data instead. it's look like it overide screen1 data. |
@HeroSony, I am facing the same issue. Have you found any solution for this? |
@chintanbawa I don't think my implementation is follow the right one but it works. If there are a better solution I will consider to pick that instead. Here it is:
|
Thanks @HeroSony for your reply and explanation. |
Hi @HeroSony, I have found the problem. Problem: Screen 1 is not updating because Solution: To fix the problem rather than using I hope this will help you and others. Thank you once again. |
Anyone getting below error message when trying to navigate using a random key?
Relevant app code:
In CollectReportScreen I call:
Which gives the error: Environment
|
@sparcbr same hear |
Anyone have a solution for this in v5? Haven't ran into a fix yet. |
in some NavigationService you can do:
in the screen given by routeName
|
Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro. |
Current Behavior
Expected Behavior
Other details
NavigationActions.navigate({ routeName: 'UserInfo', params: {userId} });
const newState = AppNavigator.router.getStateForAction(action, state);
Your Environment
The text was updated successfully, but these errors were encountered: