最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular 2 get previous page url - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 11

UPDATED 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.

发布评论

评论列表(0)

  1. 暂无评论