Angular 6 updateupdated code for getting previous url as string;string.
import { RouterComponent, NavigationEnd,OnInit ActivatedRoute,} NavigationStart,from NavigationCancel'@angular/core'; import { Router, RoutesRecognized } from '@angular/router'; import { filter, pairwise } from 'rxjs/operators'; export class AppComponent implements OnInit { constructor ( public router: Router ) { } ngOnInit() { this.router.events .pipe(filter((e: any) => e instanceof RoutesRecognized), pairwise() ).subscribe((e: any) => { console.log(e[0].urlAfterRedirects); // previous url }); } }