解决在角度2中不要求使用子路线的问题 [英] Resolve not called for child routes in angular 2

查看:74
本文介绍了解决在角度2中不要求使用子路线的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

路由器详细信息:

这是正在延迟加载的功能部件模块的路由详细信息. 路线是/customers

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

];

在2个解析器中,我只是写到已到达解析器的控制台.

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

如果我输入以下网址:

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

2个解析器被执行.

如果我按下在我的ts中执行以下操作的按钮:

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

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

仅执行第一个解析器!

作为我最里面的组件"CustomersModuleDetailsComponent"显示信息 根据url,由于未执行该组件的解析器,因此未刷新.

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.

有什么建议吗? (除了将解析器更改为警卫人员之外) (并且除了通过@input或eventEmitter将ID从父组件传输到子组件之外)

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)

谢谢

推荐答案

我遇到了同样的问题.看来Angular Router中有一个错误.

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.

这篇关于解决在角度2中不要求使用子路线的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆