-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
refactor(router): compute correct history restoration when navigation is cancelled #38884
refactor(router): compute correct history restoration when navigation is cancelled #38884
Conversation
e2b10a5
to
add1b74
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @aahmedayed - this looks promising! What do you think of breaking this up into two PRs? I think a PR to add go
/goTo
as a feature separately would be valuable on its own. Then have a separate PR to fix the routing history with guards. This would make the review process much easier.
I haven't reviewed the changes to the router yet, as that will take a little more time and careful review.
Hi @atscott - thank you for your review, and yes i think it’s a good idea to have the solution into two PR’s. |
6e7416a
to
894f5d0
Compare
Hi @atscott - I’ve already finished the adjustments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking better :) I've added another round of comments.
I think you may have missed one of my comments about a request to add some more testing around the history in some scenarios:
- An error during navigation (this was why we moved some logic to
finalize
) - a route being cancelled by a canLoad guard
- a route being cancelled by a resolver returning
EMPTY
Adding the |
4a1fb91
to
524762e
Compare
You're the most welcome @AndrewKushnir and thanks a lot @atscott |
… is cancelled (#38884) We can’t determine whether the user actually meant the `back` or the `forward` using the popstate event (triggered by a browser back/forward) so we instead need to store information on the state and compute the distance the user is traveling withing the browser history. So by using the `History#go` method, we can bring the user back to the page where he is supposed to be after performing the action. implementation for #13586 PR Close #38884
Hi @aahmedayed, I had a thought tonight about this and realized we missed a pretty important scenario. It's very common for guards to schedule a new navigation before returning A specific scenario where this doesn't work:
There might be other scenarios I haven't thought of. I'll be on vacation until July. If you get a chance to take a look and send a PR before then, I can review it when I'm back. Otherwise I'll see about investigating other scenarios, making some adjustments to the code, and then start thinking about making the option public opt-in. |
@aahmedayed I've been working with this more today and I'm a little concerned that this won't work in the end. We can always figure out how to handle things when navigations go through the back/forward buttons or through Edit: Playing with this in a real application, it seems like browsers retain information about the origin of the navigation. This means that if I am going between pages that cross a manual navigation boundary, it treats that as a non-SPA navigation so the |
When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in angular#38884 (comment)
When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in angular#38884 (comment)
When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in angular#38884 (comment)
When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in angular#38884 (comment)
When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in angular#38884 (comment)
When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in angular#38884 (comment)
When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in angular#38884 (comment)
When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in angular#38884 (comment)
When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in angular#38884 (comment)
When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in angular#38884 (comment)
When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in angular#38884 (comment)
When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in angular#38884 (comment)
When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in angular#38884 (comment)
When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in angular#38884 (comment)
HI @atscott - Sorry for the delay I’m taking some days off, I’ll be back Monday. Thank you for all the fixes you made. |
…#42751) When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in #38884 (comment) PR Close #42751
…#42751) When another navigation is triggered during an in-process navigation and the `canceledNavigationResolution` is `'computed'`, we should not attempt to restore the browser history using `history.go`. Doing that would trigger a third navigation through the router which would conflict with the new navigation that we were trying to process. Instead, we treat this as a redirect and skip the history restoration attempt. This acts similarly to returning `UrlTree` from a guard. Fixes issue described in #38884 (comment) PR Close #42751
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
We can’t determine whether the user actually meant the
back
orthe
forward
using the popstate event (triggered by a browserback/forward)
so we instead need to store information on the state and compute the
distance the user is traveling withing the browser history.
So by using the
History#go
method,we can bring the user back to the page where he is supposed to be after
performing the action.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information