I have two ponents. Customer and Shipment ponents. When user e from Shipment ponent to Customer ponent. I want to Customer ponent direct to Shipment ponent.
I use this method.
this._location.back();
from Location angular/mon.
This method every always direct to back page. But I want direct to just when i came from shipment ponent.
I have two ponents. Customer and Shipment ponents. When user e from Shipment ponent to Customer ponent. I want to Customer ponent direct to Shipment ponent.
I use this method.
this._location.back();
from Location angular/mon.
This method every always direct to back page. But I want direct to just when i came from shipment ponent.
Share Improve this question asked May 4, 2017 at 8:58 NadirCan KAVKASNadirCan KAVKAS 1591 gold badge4 silver badges16 bronze badges 1-
1
You can use
pairwise
like shown in stackoverflow./questions/33520043/… and store the current and previous value in a service – Günter Zöchbauer Commented May 4, 2017 at 9:01
1 Answer
Reset to default 11UPDATED for Angular 6
Insert the code below to your parent ponent, which contains your 2 ponents:-
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.