简体   繁体   中英

Angular 8 - Lazy Loading of Module not working

As shown in https://stackblitz.com/edit/angular-qbbhgp , I am trying to achieve a very simple routing which involve lazy loading of module. When I click on the "link", it seems not working. I expected to see the word "Student Page" appear, but it did not happen.

Note that I would like the solution to involve the use of import api (the newer syntax to lazy load module)

It's because you haven't added routing to your student module.

Fork of your stackblitz: https://stackblitz.com/edit/angular-zrnrxj

The student module needs to use .forChild() when declaring routes since it is a child module.

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

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

You have not provided a Routes for Student.routing.module ?

Since you have directed the student.module , but you might have not provided from there what component you have been show.

If you have not created to Student.routing.module , create one and provide a default route in the same module.

const routes: Routes = [

  {path: '', component:StudentComponent } ];

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM