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
fix(router): don't break history when CanDeactivate cancel back navigation #13922
Conversation
058bc2b
to
d1667ff
Compare
72d5b67
to
038d91b
Compare
@vicb Review when you get a chance. |
038d91b
to
96b0b21
Compare
@DzmitryShylovich could toy please rebase the PR ? |
@@ -613,14 +613,6 @@ export class Router { | |||
Promise<boolean> { | |||
const lastNavigation = this.navigations.value; | |||
|
|||
// If the user triggers a navigation imperatively (e.g., by using navigateByUrl), |
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.
why is this removed ?
I don't think it relates to the issue ?
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 check breaks this test.
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.
there're no unit tests for this so I'm not sure what uses cases it covers
this.resetUrlToCurrentUrlTree(); | ||
this.routerEvents.next(new NavigationCancel(id, this.serializeUrl(url), '')); | ||
const navigatedUrl: string = this.serializeUrl(url); | ||
// When navigation is canceled and it was initiated by the click on Back button, |
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.
What if was the forward button ?
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.
see inline comments
96b0b21
to
81f02d2
Compare
@vicb rebased
if
does it make sense? the biggest problem is to figure out when back/forward button is called |
Fixed moved to #18135 |
feel sad for problem remained on 4.3 |
This issue is it fixed ? |
Does not seem like it is #13586 (comment) |
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. |
Closes ##13586
Description:
location.back()
is called before router so there's no way to prevent if whenCanDeactivate
returnfalse
.To maintain proper history we need to push (
location.pushState
) new entry into the history instead of replacing (location.replaceState
) the current entry.History before the fix
After the fix
TLTR our goal: we need to call
location.pushState
instead oflocation.replaceState
whenCanDeactivate
cancelsback
navigationhttp://plnkr.co/edit/GMkEl74JkQiRPMv6Km5Z?p=preview