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:
You may use canDeactivate guard when defining route, this will help you writing logic when changing route.
You may simply return true or false, based upon if you want to continue or reject route navigation, you also get reference to your component instance which is active for that route so as to read any property on it.
Signature of the method is like below,
canDeactivate(component: T,
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot) :
Observable<boolean>|Promise<boolean>|boolean
You may read more about it here