1//Update angular 6+
2//The events.filter gives error because filter is not part of events, so change the code to
3
4import { filter, pairwise } from 'rxjs/operators';
5
6this.router.events
7.pipe(filter((evt: any) => evt instanceof RoutesRecognized), pairwise())
8.subscribe((events: RoutesRecognized[]) => {
9 console.log('previous url', events[0].urlAfterRedirects);
10 console.log('current url', events[1].urlAfterRedirects);
11});
1 // private router: Router//inject
2 this.router.events
3 .pipe( filter( (evt:any)=>evt instanceof RoutesRecognized),pairwise())
4 .subscribe((events: RoutesRecognized[]) =>{
5 console.log('previous',events[0].urlAfterRedirects);//previous url
6 console.log('current url',events[1].urlAfterRedirects);//current url
7 } );