I would like to cancel the route change when the user click back or forward button in the browser. So far I manage to capture the route change event as in the code below:
constructor(router:Router) {
router.events
.subscribe((event:Event) => {
// some logic.
// event.preventDefault(); ?
});
}
I couldn't find any method / member in event to stop the event default. Then I will get this error on console because I have no route config registered as intended, this is because I use location.go()
to modify the url.
Error: Uncaught (in promise): Error: Cannot match any routes: 'Some/Url'
Is there any way to cancel the route change so Angular doesn't look at the route config?
See Question&Answers more detail:os