I have two components. Customer and Shipment components. When user come from Shipment component to Customer component. I want to Customer component direct to Shipment component.
I use this method. 
this._location.back(); from Location angular/common.
This method every always direct to back page. But I want direct to just when i came from shipment component.
UPDATED for Angular 6
Insert the code below to your parent component, which contains your 2 components:-
import { Router, RoutesRecognized } from "@angular/router";
import { filter, pairwise } from 'rxjs/operators';
previousUrl:string;
constructor(private router: Router) {
    router.events
        .pipe(
          filter(event => event instanceof RoutesRecognized),
          pairwise()
        )            
        .subscribe((e: any) => {
            this.previousUrl = e[0].urlAfterRedirects;
        });
}
It worked for me, I hope it will work for you as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With