Angular2 Component不会为参数化路由重新初始化

Mus*_*afa 5 typescript angular2-routing angular

我在测试路线下面有参数T1:

{
    path: 'Test/:T1',
    component: TestComponent
},
Run Code Online (Sandbox Code Playgroud)

当我从'Test/1'路由到'Test/2'时,我TestComponent没有重新初始化.这是角度路由器的问题吗?

我在用 "@angular/router": "3.0.0-beta.1"

Gün*_*uer 2

这是目前唯一支持的行为。有计划使其可配置https://github.com/angular/angular/issues/9811

您可以订阅参数更改并在那里进行初始化

export class MyComponent {
    constructor(private route : ActivatedRoute,
      private r : Router) {}

    reloadWithNewId(id:number) {
        this.r.navigateByUrl('my/' + id + '/view');
    }

    ngOnInit() {
      this.sub = this.route.params.subscribe(params => {
         this.paramsChanged(params['id']);
       });
    }

    paramsChanged(id) {
      console.log(id);
      // do stuff with id

    }
}
Run Code Online (Sandbox Code Playgroud)

另请参阅如何手动重新渲染组件?