Skip to main content
added 120 characters in body
Source Link
Franklin Pious
  • 3.9k
  • 3
  • 29
  • 31

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 }); } } 

Angular 6 update code for getting previous url as string;

import { Router, NavigationEnd, ActivatedRoute, NavigationStart, NavigationCancel, RoutesRecognized } from '@angular/router'; 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 }); } } 

Angular 6 updated code for getting previous url as string.

import { Component, OnInit } from '@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 }); } 
Source Link
Franklin Pious
  • 3.9k
  • 3
  • 29
  • 31

Angular 6 update code for getting previous url as string;

import { Router, NavigationEnd, ActivatedRoute, NavigationStart, NavigationCancel, RoutesRecognized } from '@angular/router'; 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 }); } }