【问题标题】:Force route transition to same route with different param in Angular 2在Angular 2中强制路由过渡到具有不同参数的相同路由
【发布时间】:2017-06-19 20:22:09
【问题描述】:

当我去相同的路线但不同的参数时,在 UI 路由器的角度 1 中。 Angular 将重新加载视图。但在 Angular 2 中却没有。它只是更新数据。但我需要用户感觉页面正在转换到不同的页面。

我已经尝试过强制 angular 2 路由到虚拟路由/组件,然后返回指定路由。当从一条路线过渡到另一条路线时,我正在使用角度动画。所以这个方法有一点延迟,看起来很奇怪。

{path: "product/:id" }

routerLink="/product/30"

【问题讨论】:

    标签: angular angular2-routing


    【解决方案1】:

    这个答案很有帮助 https://stackoverflow.com/a/38129910/9027171

    1 - 你应该添加 ActivatedRoute

    import {Router, ActivatedRoute} from '@angular/router';
    

    2 - 在构造函数中

    构造函数(私有激活路由:ActivatedRoute,...

    3 - 在 ngOnInit() 上:

    this.activatedroute.params.subscribe(params => {
          console.log(params, params['rowid']);
          this.id = params['rowid']
            }
        });
    

    订阅后您的参数将在导航后更改 注意:参数['here_put_your_param_name']

    谢谢你:)

    【讨论】:

      猜你喜欢
      • 2019-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 2018-01-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多