Angular 8-模块的延迟加载不起作用

问题描述 投票:0回答:3

https://stackblitz.com/edit/angular-qbbhgp所示,我试图实现一个非常简单的路由,其中​​涉及模块的延迟加载。当我单击“链接”时,它似乎无法正常工作。我希望看到“学生页面”一词出现,但是没有发生。

请注意,我希望解决方案包括使用import api(惰性加载模块的较新语法)

angular routes load lazy-evaluation
3个回答
0
投票

这是因为您尚未将路由添加到学生模块。

您的堆叠闪电叉:https://stackblitz.com/edit/angular-zrnrxj

由于学生模块是子模块,因此学生模块在声明路由时需要使用.forChild()

const routes:Routes = [
  { path: '', component: StudentComponent } 
]

@NgModule({
  imports: [
    CommonModule,
    RouterModule.forChild(routes)
  ],
  declarations: [StudentComponent]
})
export class StudentModule { }

0
投票

您必须定义延迟加载模块的路由并指定延迟加载模块的根组件。


0
投票

您还没有为Student.routing.module提供路由?

由于您已经指导了student.module,但是您可能没有从那里提供所显示的组件。

如果尚未创建到Student.routing.module,请在同一模块中创建一个并提供默认路由。

const routes: Routes = [

  {path: '', component:StudentComponent } ];
© www.soinside.com 2019 - 2024. All rights reserved.