【问题标题】:How to transit to other routes using the same component without destroying and reinitializing Component?如何在不销毁和重新初始化组件的情况下使用相同的组件传输到其他路由?
【发布时间】:2016-04-26 06:33:43
【问题描述】:

我有一个 ProfileComponent,在页面内用户可以点击字母来过滤以它开头的配置文件。

入口点:/profile

A B C ... X Y Z

当用户点击这些字母时 -> url:/profile -> /profile/;startWith=X.

我想在 URL 中保留 startWith 参数,但是我注意到 Angular 2 会破坏当前组件,然后重新创建并再次初始化相同的组件。如何在不重新初始化组件的情况下保留 URL 参数?

【问题讨论】:

    标签: angular router


    【解决方案1】:

    如果你实现CanReuse

    routerCanReuse(next: ComponentInstruction, prev: ComponentInstruction) { return true; }
    

    在您的组件中,路由器应该保留相同的实例,而不是重新创建一个新实例。

    【讨论】:

      猜你喜欢
      • 2017-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-14
      • 2015-07-18
      • 2020-07-16
      • 2017-01-09
      • 2013-06-07
      相关资源
      最近更新 更多