Resolve not called for child routes in angular 2

穿精又带淫゛_ 提交于 2020-06-12 21:20:37

问题


router details:

this is the route details of a feature module, being lazy loaded. the route is /customers

const routes: Routes = [
{ path: '',
component: CustomersComponent,
children: [
  { path: '',    component: CustomersListComponent },
   { path: ':id',    component: CustomersDetailsComponent,
   resolve: {
      xxx: CustomerResolve1
    }
    ,children: [
     { path: ':module',    component: CustomersModuleDetailsComponent,
    resolve: {
      xxx: CustomerResolve2
    }
   }
   ] }
 ]
}

];

in the 2 resolvers, i just write to the console that i've reached the resolver.

if i enter the following url:

http://localhost:4200/customers/45/invoices

the 2 resolvers are executed.

if i press a button that executes the following in my ts:

this.router.navigate(['customers','100','invoices']);

only the first resolver is executed !

as my inner most component "CustomersModuleDetailsComponent" shows information based on the url, it's not being refreshed as the resolver for that component isn't being executed.

any suggestions ? (beside changing the resolver to a guard) (and besides transferring the id from the father component to the son component via @input, or eventEmitter)

Thanks


回答1:


I have the same issue. It seems there is a bug in Angular Router.

The children's resolvers are not triggered in this case when parent route param is modified.



来源:https://stackoverflow.com/questions/41496499/resolve-not-called-for-child-routes-in-angular-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!