简体   繁体   中英

Lazy module not found in Angular version 11

This app is trying to load the BookModule lazily with this configuration:

const routes: Routes = [
  { path: "", redirectTo: "/books", pathMatch: "full" },
  {
    path: "books",
    loadChildren: "./modules/book/book.module#BookModule",
    canActivate: [AuthGuard]
  },
  { path: "login", component: LoginComponent }
];

And it's producing the error:

Error: Cannot find 'BookModule' in './modules/book/book.module'

Thoughts?

Seems like your Angular version is 11.

The lazy loading syntax changed. It is something like this now

const routes: Routes = [
  {
    path: 'items',
    loadChildren: () => import('./items/items.module').then(m => m.ItemsModule)
  }
];

So your code should be like this

const routes: Routes = [
  { path: "", redirectTo: "/books", pathMatch: "full" },
  {
    path: "books",
    loadChildren: () => import('./modules/book/book.module').then(m => m.BookModule),
    canActivate: [AuthGuard]
  },
  { path: "login", component: LoginComponent }
];

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