if you read the code it returns the this.previousUrl = this.currentUrl. I think its great if people spent time and contribute to community, but they should make sure what they post its valid.
Here is the revised code which works at least for me
import { Injectable } from '@angular/core'; import { Router, NavigationEnd, RoutesRecognized } from '@angular/router'; import {filter, pairwise } from 'rxjs/operators'; @Injectable() export class PreviousRouteService { private previousUrl: string; constructor(private router: Router) { this.router.events .pipe(filter((evt: any) => evt instanceof RoutesRecognized), pairwise()) .subscribe((events: RoutesRecognized[]) => { this.previousUrl = events[0].urlAfterRedirects; console.log('previous url', this.previousUrl); }); } public getPreviousUrl() { return this.previousUrl; } }
Big thanks, bro. Digging a lot and only your solution works.
Thank you bro! Your solution works very well.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
if you read the code it returns the this.previousUrl = this.currentUrl. I think its great if people spent time and contribute to community, but they should make sure what they post its valid.
Here is the revised code which works at least for me
Big thanks, bro. Digging a lot and only your solution works.
Thank you bro!
Your solution works very well.