-
Notifications
You must be signed in to change notification settings - Fork 13.5k
bug: ion-router can set wrong url after nav changes #24223
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
Comments
Thanks for the issue. Can you please reproduce this issue in an Ionic core starter app and provide a link to the repo? |
Thanks for the issue! This issue has been labeled as Please reproduce this issue in an Ionic starter application and provide a way for us to access it (GitHub repo, StackBlitz, etc). Without a reliable code reproduction, it is unlikely we will be able to resolve the issue, leading to it being closed. If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for our team to reproduce the issue. For a guide on how to create a good reproduction, see our Contributing Guide. |
Created a repo that reproduces the issue. https://github.com/cjorasch/issue-24223 To reproduce:
There will now be 3 views in the stack
The view will pop back to Additional details are available in the Javascript console. |
Another related issue that I noticed is that the router has problems if you push content onto the nav stack using a component and props directly vs. something that maps to a url. nav.push('my-content-page', { ... }); In this case the view is displayed but the router logs an error When you click the back button you pop to the prior view but the url is reset to |
@cjorasch thanks for the reported issue and extremely thorough analysis/replication! This indeed appears to be a bug with the logic used to find the best path match based on the navigation state. I'll explore your suggested change to We'll update you when we have something new to share 👍 |
I am currently using the 6.0 branch so I am not able to test in our main app but I can take a look with the repro app to see if I see any issues. Thanks! |
I did some tests in the repro app and things looked like they are working correctly. I can test in our main app when it gets moved to the 6.0 branch. |
Great! This fix will also be in the next Ionic 6 RC. I am going to close this out since the original issue seems to be resolved. If you run into any errors with this fix please let us know. Thank you! |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. |
Prerequisites
Ionic Framework Version
Current Behavior
If the same component is used to render more than one route then the router can set the wrong url after navigation.
For example, when the user clicks the
<ion-back-button>
the url can be left unchanged or can be cleared entirely.Any code that looks at the url will be using an incorrect value, the browser history will be incorrect, refreshing the page will change the content, etc.
Expected Behavior
Navigating back should result in the router setting the correct url.
Steps to Reproduce
If the following routes are defined:
And the user navigates through the following steps:
If the routes are defined in reverse order:
And the user navigates through the following steps:
After clicking on the ionic back button,
<ion-nav>
correctly transitions to the previous page and then callsrouter.navChanged()
to update the url path.This goes through this process:
Note: Clicking on the browser back button (instead of using
<ion-nav>
to pop the view) does not result in this problem because the path is correct and nav is able to show the page.Code Reproduction URL
No response
Ionic Info
Ionic:
Ionic CLI : 6.12.1
Utility:
cordova-res : not installed
native-run : not installed
System:
NodeJS : v14.15.0
npm : 6.14.8
OS : macOS Big Sur
Additional Information
This is related to a previously reported issue but I have added more details to diagnose the problem.
#23435
This bug has been driving us crazy for a long time because the routing doesn't work and we were forced to use the same component for multiple routes to work around some other bugs.
One possible change that will improve the behavior of the component is to make the following change to
path.ts
.The current code is:
If the case for a param not found is changed to return the path that has matched so far (vs. null) and the routes are defined in order of most params to least params then it is possible to work around the problem.
This allows it to return the portion of the path that it was able to resolve vs. returning null and resulting the the url not changing when clicking back.
A better solution would be to change the logic for the route matching to find the correct route based on the params but it is little harder to understand if that would impact other logic.
The text was updated successfully, but these errors were encountered: