延迟加载模块的子节点上的角度路由问题

时间:2019-08-21 17:01:20

标签: angular angular7 angular7-router

Iam在路由惰性加载模块的子节点时遇到问题,它会在单击链接时重定向,但在刷新时会显示abc / runtime.js

它重定向,但刷新后会出现此错误

 GET http://localhost:4200/research-institutes/runtime.js net::ERR_ABORTED 404 (Not Found)

应用模块路由

           path:'',
           component:DefaultComponent,
           children: [
                 {
                   path:'research-institutes',
                   loadChildren:'../../src/app/views/research-institutes/research-institutes.module#ResearchInstitutesModule'
           }

]

延迟加载的模块路由

const routes: Routes = [
    {
       path:'',
     component:InstitutesListingComponent
   },
   {
     path:'detail',
     component:InstituteDetailComponent
   }
];

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

1 个答案:

答案 0 :(得分:0)

根据Angular documentation,使用延迟加载的正确方法是

{
  path:'research-institutes',
  loadChildren: () => import('../../src/app/views/research-institutes/research-institutes.module').then(m => m.ResearchInstitutesModule)
 }
相关问题