【问题标题】:problem with lazy loading in nested child routing , angular. Cannot access to the view嵌套子路由中延迟加载的问题,角度。无法访问视图
【发布时间】:2020-09-04 21:49:40
【问题描述】:
const routes: Routes = [
  {
    path: "",
    component: LayoutComponent,
    data: { breadcrumbs: 'Home' },
    children: [
      {
        path: 'home',
        component: HomeComponent
      },
      {
        path: 'configurazione',
        data: { breadcrumbs: 'configurazione' },
        component: ConfigurazioniComponent,
        children : [
          {
            path:'protocollo',
            loadChildren:()=>import("./modules/protocollo/protocollo.module").then(
              (m)=>m.ProtocolloModule
            ),
          }
        ]
      }]

从此代码我无法加载 ProtocolloModule。当我从路线上写“configurazione/protocollo”时,我被困在了“configurazione”路径中。我该如何解决这个问题? 如果我从第二个孩子中插入 loadModule 一切都很好。我怎样才能让它以这种方式工作?

【问题讨论】:

标签: angular routes angular2-routing


【解决方案1】:
const routes: Routes = [
  {
    path: '',
        component: ProtocolloGestioneComponent,
        data: { breadcrumbs: 'Protocollo' },
    children: [
      {
        path: 'crea',
        component: ProtocolloCensimentoSidenavComponent,
        canDeactivate : [CanDeactivateGuard]
      }
    ],  
  },
  { path: '**', redirectTo: '' }
]

@NgModule({
  declarations: [],
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class ProtocolloRoutingModule { }

这是协议的路由,我不明白缺少什么或者我还没有把它放在嵌套的方式中。

【讨论】:

    【解决方案2】:

    我设法使它工作。 组件配置模板中没有。现在我有另一个问题,在配置/协议中我既有配置模板也有协议模板,好像指令没有从视图切换

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-21
      • 2018-04-23
      • 1970-01-01
      • 2022-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多