-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Returning false from canDeactivate removes history entry (browser history back) #302
Comments
I have workaround for this issue, but it seems dirty... Idea is return redirect to previous page to avoid loosing navigation history. How to apply: import {Router, Redirect} from 'aurelia-router'; inject router static inject(){
return [Router];
}
constructor(router){
this.router = router;
} in canDeactivate change return confirm('Are you sure you want to leave?'); to if(!confirm('Are you sure you want to leave?')){
return new Redirect(this.router.history.previousLocation, {trigger:false, replace: false});
} And still, is there some non dirty way to achieve same behavior? |
Hi, I am experiencing the same problem, thanks for your workaround, it saves my day ! |
as another not very clean temp workaround - you can call
|
The history entry that is being removed should be the one that was cancelled. So, it makes sense for that to be removed, given that that route was never actually allowed to activate or be visited. If you want different behavior, then using a redirect is a perfectly valid solution. |
I agree with @EisenbergEffect 's comment to some extent. While it seems perfectly valid to me that a cancelled navigation should not have an history entry, removing an entry from the history stack seems illogical. An entry that is in the stack has already been visited, it's not one that is being added. If the entry is removed, the history is left inconsistent (in this case, doing back again would look like jumping 2 steps in the history). IMO, This is a duplicate of #528 which has been assigned to @davismj |
When navigating back by browser history and return false from canDeactivate, then history record is removed (replaced).
How to reproduce:
Effect:
"Child Router" page is open instead of "Github Users"
Additional:
If you repeat 6-7 steps few times more, application will close without promt, since application history becomes empty.
Question:
Is any way to do not allow deactivate without loosing navigation history?
It will be logical, for example if I have "users" page, then go to user editing, edit something without saving changes, on browser back I'm asked if I want to leave without saving changes, I choose - no, then save changes, and press history back again. In such case I expect return back to "users" page instead of somewhere else where I was earlier.
The text was updated successfully, but these errors were encountered: