angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.56k stars 3.01k forks source link

Extra transition fired when other state has same final url, but with query param added #3715

Closed dietergeerts closed 4 years ago

dietergeerts commented 6 years ago

This is a (check one box):

My version of UI-Router is: v1.0.11 (but bug still on v1.0.16)

Bug Report

Background

In our application, we work with collections, where each collection has kind of a workflow they go through. The URL for each collection should be the same, but the page, and thus the state, will be different depending on the state. That's the reason why we create sibling states, which have the same final URL, but have a different view. We then use redirectTo in order to redirect to the correct state depending on the phase.

Current Behavior:

When going directly to a certain sibling state, that transition starts, and succeeds. BUT when one of the sibling states has query params, another transition is triggered, eventually leading up to the first one because of redirectTo system. So in a sense, it should be no problem. BUT we have a check on dirty forms, so we can notify the user that there are unsaved changes, and thus show a modal to ask what to do with them. Doing the first transition, we add a custom option to skip this check, as at that point, we know we'll not transition away from the form, as it's just updating the hash param to navigate to the form sections. BUT because that second transition is triggered, and that custom options isn't there, the check is performed and the modal shows up.

Expected Behavior:

When navigating directly to one of those sibling states that have the same final URL, there should not be an extra transition triggered because one of them has extra query params.

Link to Plunker or stackblitz that reproduces the issue:

https://next.plnkr.co/edit/C2CYgrRfeeNnjF6kLcQX

I also tried some workarounds and left them commented in the Plunker, so other that experience this can apply it in the meantime.

dietergeerts commented 6 years ago

For some reason, the described workaround, which works in the Plunker, doesn't work in our real code, so I believe the bug goes deeper than just having the query params there or not.

EDIT: Adding the query params to the shared parent state is the workaround.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues may be reopened.

Thank you for your contributions.