Answers for "get previous url angular"

3

angular how to check previous route

//Update angular 6+
//The events.filter gives error because filter is not part of events, so change the code to

import { filter, pairwise } from 'rxjs/operators';

this.router.events
.pipe(filter((evt: any) => evt instanceof RoutesRecognized), pairwise())
.subscribe((events: RoutesRecognized[]) => {
  console.log('previous url', events[0].urlAfterRedirects);
  console.log('current url', events[1].urlAfterRedirects);
});
Posted by: Guest on December-12-2020
0

get previous url angular

// private router: Router//inject
    this.router.events
    .pipe( filter(        (evt:any)=>evt instanceof RoutesRecognized),pairwise())
    .subscribe((events: RoutesRecognized[]) =>{        
        console.log('previous',events[0].urlAfterRedirects);//previous url
        console.log('current url',events[1].urlAfterRedirects);//current url
      }    );
Posted by: Guest on July-11-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language