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.
constr
import { HostListener } from '@angular/core';
and then listen for popstate on the window object:
popstate
window
@HostListener('window:popstate', ['$event']) onPopState(event) { console.log('Back button pressed'); }
This code works for me on latest Angular 2.