Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
97 views
in Technique[技术] by (71.8m points)

javascript - 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?

question from:https://stackoverflow.com/questions/65866864/lazy-module-not-found-in-angular-version-11

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 }
];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...