How can I detect if a user has pressed the back button in their browser to navigate back while using Angular?
Currently, I am subscribing to router events to achieve this.
constructor(private router: Router, private activatedRoute: ActivatedRoute) {
this.routerSubscription = router.events
.subscribe(event => {
// if (event.navigatesBack()) ...
});
}
Although I am aware that I can use window.onpopstate
to achieve the same result, it feels like a workaround when working with Angular2.