【问题标题】:Fire ActivateRoute subscribe event when URL params changes当 URL 参数更改时触发 ActivateRoute 订阅事件
【发布时间】:2016-09-26 05:36:17
【问题描述】:

有这个子组件路由:

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

更改当前 URL http://localhost:5555/dashboard/USERNAME/conso 使用另一个用户名:

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

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

我也尝试ApplicationRef.tick(),订阅也没有被调用。

【问题讨论】:

    标签: angular


    【解决方案1】:
    this.sub = this.route.url.subscribe(
          ....
        );
    

    【讨论】:

      猜你喜欢
      • 2022-01-08
      • 1970-01-01
      • 1970-01-01
      • 2021-10-05
      • 1970-01-01
      • 2021-02-27
      • 1970-01-01
      • 2015-09-28
      • 2018-07-07
      相关资源
      最近更新 更多