routerCanDeactivate()
successfully prevents navigation away from component.
routerCanDeactivate(nextInstruction: ComponentInstruction, prevInstructi
Due to window.onpopstate
triggering at every back button click,
I thought that a pushState
will be required. But that wasn't the case, and following code works perfectly.
routerCanDeactivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction) {
if(confirm("Do you want to discard unsaved changes ?")){
return true;
}
else {
history.forward();
return false;
}
}
But it would be nice if somebody could explain what is happening because I don't have much knowledge of history api
.