Parameters Angular 2路由器传递参数并在更改时获取

Parameters Angular 2路由器传递参数并在更改时获取,parameters,angular,onchange,router,Parameters,Angular,Onchange,Router,如何将一些参数传递给我的死记硬背,就像在旧路由器中一样 旧的 新的 然后让他们订阅更改 export class AppComponent { public constructor(private router: Router) { this.router.changes.subscribe((x) => { console.log(x); }); 我的意思是,在旧的angular中有一

如何将一些参数传递给我的死记硬背,就像在旧路由器中一样

旧的

新的

然后让他们订阅更改

 export class AppComponent {

        public constructor(private router: Router) {

            this.router.changes.subscribe((x) => {
                console.log(x);
            });

我的意思是,在旧的angular中有一个状态,我们可以附加事件
onBefore
ect并获得当前状态。实际上这在这里是如何工作的
this.router.changes.subscribe
-它正在触发更改,但不提供任何有关它的信息-
x
未定义。

订阅中不再存在任何参数。您需要使用位置服务检查当前路线:

import {Location} from '@angular/common';
import {Router} from '@angular/router'

export class SomeComponent {
  constructor(router:Router, private location:Location) {
    router.changes.subscribe(() => this.routeChanged());
  }

  private routeChanged():void {
    var path:string = this.location.path();
    console.log("Path:" + path);
  }
}

订阅中不再存在任何参数。您需要使用位置服务检查当前路线:

import {Location} from '@angular/common';
import {Router} from '@angular/router'

export class SomeComponent {
  constructor(router:Router, private location:Location) {
    router.changes.subscribe(() => this.routeChanged());
  }

  private routeChanged():void {
    var path:string = this.location.path();
    console.log("Path:" + path);
  }
}
import {Location} from '@angular/common';
import {Router} from '@angular/router'

export class SomeComponent {
  constructor(router:Router, private location:Location) {
    router.changes.subscribe(() => this.routeChanged());
  }

  private routeChanged():void {
    var path:string = this.location.path();
    console.log("Path:" + path);
  }
}