Angular2 router 2.0.0 not reloading components when same url loaded with different parameters?

前端 未结 5 685
轮回少年
轮回少年 2020-11-27 06:34

I have this in my .routing.ts file

export const routing = RouterModule.forChild([
{
    path: \'page/:id\',
    component: PageComponent
}]);
5条回答
  •  野性不改
    2020-11-27 07:19

    update 2

    This answer is only for a long ago discontinued router version.

    See https://angular.io/api/router/RouteReuseStrategy for how to do it in the current router.

    update 1

    That's now fixed (Angular 2.3) for the new router by https://github.com/angular/angular/pull/13124 which allows to provide a custom reuse strategy.

    For an example see also https://www.softwarearchitekt.at/post/2016/12/02/sticky-routes-in-angular-2-3-with-routereusestrategy.aspx

    original

    https://github.com/angular/angular/issues/9811

    That's a known issue. Currently there is no way to make the router re-create the component on parameter-only route changes.

    They discussed plans to implement some reuse-strategies eventually.

    You can subscribe to params changes and execute your code there instead of in ngOnInit()

提交回复
热议问题