【问题标题】:Resolve not called for child routes in angular 2解决角度 2 中不要求子路由的问题
【发布时间】:2017-01-05 23:26:12
【问题描述】:

路由器详情:

这是一个特性模块的路由细节,被延迟加载。 路线是 /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 个解析器中,我只是写信给我已经到达解析器的控制台。

如果我输入以下网址:

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

执行 2 个解析器。

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

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

只执行第一个解析器!

作为我最里面的组件“CustomersModuleDetailsComponent”显示信息 基于 url,它不会被刷新,因为该组件的解析器没有被执行。

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

谢谢

【问题讨论】:

  • 你应该使用绝对路径名
  • @RomanC 你能解释一下吗?
  • 老兄,你应该把这个添加到你的路由器配置中:)
  • @RomanC 如何使用延迟加载模块来做到这一点?上述路线属于功能模块。 “/customers”路径在 app.module.routing.ts 中定义

标签: angular router resolve


【解决方案1】:

我也有同样的问题。 Angular 路由器中似乎有一个错误。

在这种情况下,修改父路由参数时不会触发子解析器。

【讨论】:

  • 这确实是路由器的问题,在 4.0 beta 3 版本中已修复。
  • 有效:路由器:当上游参数改变时调用解析器(#12942)(d4d3782
猜你喜欢
  • 1970-01-01
  • 2014-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-06
  • 1970-01-01
  • 2019-01-18
  • 2020-05-21
相关资源
最近更新 更多