The pairwise
operator allows to get the current together with the previous value
update
import 'rxjs/add/operator/pairwise';
import 'rxjs/add/operator/filter';
import { Router, NavigationEnd } from '@angular/router';
export class AppComponent {
constructor(private router: Router) {
this.router.events
.filter(e => e instanceof NavigationEnd)
.pairwise().subscribe((e) => {
console.log(e);
});
}
}
See also How to detect a route change in Angular?
original (super old)
Inject Router
and subscribe to events and store them for later reference
constructor(private _router: Router) {
this._router.subscribe(route => {
this.nextRoute ...
this.prevRoute ...
});