I have a component and I need to detect if user pressed back button in his browser to navigate back.
Currently I'm subscribing router events.
constructor(private router: Router, private activatedRoute: ActivatedRoute) {
this.routerSubscription = router.events
.subscribe(event => {
// if (event.navigatesBack()) ...
});
}
I know that I can use window.onpopstate
but it feels like a hack when using Angular2.