Angular6更新了获取前一个URL作为字符串的代码。
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});}
