当URL参数更改时,激活ActivateRoute订阅事件

时间:2016-09-25 21:07:24

标签: angular

有这个子组件路线:

export const ConsoRoutes: Route[] = [
    {
        path: 'conso',
        component: ConsoComponent
    },
  {
    path: 'conso/:grain',
    component: ConsoComponent
  }
];

export class ConsoComponent implements OnInit {
....
    ngOnInit() {
    this.sub = this.route.params.subscribe(params => {
      var grain = params['grain'];
      ....
      reload some charts.  
    }
 }

查看当前网址http://localhost:5555/dashboard/USERNAME/conso 使用另一个用户名:

this.$router.navigateByUrl(this.$router.url.replace(this.username, newUsername));

没有触发this.route.params.subscribe,如何强制订阅活动?

我也尝试ApplicationRef .tick(),也不会调用订阅。

1 个答案:

答案 0 :(得分:0)

this.sub = this.route.url.subscribe(
      ....
    );