且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

延迟加载在Angular 6中不起作用

更新时间:2023-01-22 13:59:46

在以前的版本中,loadChildren路径支持'app/path/to/module#Module',但它不再起作用,而是使用相对路径'./路径/到/模块#模块'

In previous versions loadChildren path support with 'app/path/to/module#Module' but it's not working anymore, instead of that use relative path './path/to/module#Module'

angular/aio/content/examples/lazy-loading-ngmodules 该示例在3天前的Angular 6版本中也已更改

angular/aio/content/examples/lazy-loading-ngmodules example also has been changed 3 days ago with Angular 6 release

https://github.com/angular/angular/commit/f44a2c730a84cd86695d1851395ad28423704bd0

Angular社区一直在回答我提出的问题,请在下面找到答复.

https://github.com/angular/angular-cli/issues/10673#issuecomment-391786453

根据角度社区的回应,他们将更新文档.

用途需要从

const routes: Routes = [
  {
    path: 'customers',
    loadChildren: 'app/customers/customers.module#CustomersModule'
  },
  {
    path: 'orders',
    loadChildren: 'app/orders/orders.module#OrdersModule'
  },
  {
    path: '',
    redirectTo: '',
    pathMatch: 'full'
  }
];

const routes: Routes = [
  {
    path: 'customers',
    loadChildren: './customers/customers.module#CustomersModule'
  },
  {
    path: 'orders',
    loadChildren: './orders/orders.module#OrdersModule'
  },
  {
    path: '',
    redirectTo: '',
    pathMatch: 'full'
  }
];

另一个提示:

One other tip:

模块导入顺序很重要 https://angular.io/guide/router#module-import-order-matters

Module import order matters https://angular.io/guide/router#module-import-order-matters