我如何使用延迟加载仅加载 angular 8 中的模块

How I can load only modules in angular 8 using lazy loading

我对延迟加载有疑问。使用 Augury 检测我的路由器树结构。

app-routing.module.ts

const routes: Routes = [
  {
    path: '',
    children: [
      {
       path: 'reservation',
          loadChildren: () => import('./modules/reservations/reservations.module').then(mod => mod.ReservationsModule)
      },
      {
        path: 'add',
        loadChildren: () => import('./modules/add-autopoint/add-autopoint.module').then(mod => mod.AddAutopointModule)
      },
      {
        path: 'availability',
        loadChildren: () => import('./modules/availability/availability.module').then(mod => mod.AvailabilityModule)
      },
      {
        path: 'archive',
        loadChildren: () => import('./modules/archive/archive.module').then(mod => mod.ArchiveModule)
      },
      { path: '**', redirectTo: '/reservation', pathMatch: 'full' },
    ]
  }
];

示例模块路由

reservation-routing.module.ts

const routes: Routes = [
  { path: '', component: ReservationComponent },
  { path: 'summary/:id', component: SummaryComponent, resolve: { summary: AtplSummaryResolver, notes: AtplNotesResolver } }
];

app.module.ts

@NgModule({
  declarations: [
    AppComponent,
    FilterPipe,
    LoaderComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    FormsModule,
    HttpClientModule,
    ReactiveFormsModule,
    SharedModule,
    NgxMatSelectSearchModule,
    FlexLayoutModule,
    AddAutopointModule,
    ArchiveModule,
    ReservationsModule,
    AvailabilityModule,
    Ng2LoadingSpinnerModule.forRoot({}),
    NavigationModule
  ],
  providers: [
    CommonService,
    AlertService,
    ListService,
    LoaderService,
    MenuService
  ],
  bootstrap: [AppComponent]
})

一开始加载这些组件是正常的还是我做错了什么?

common services, components, pipes ..., 只在懒加载的模块中使用,应该分组在Shared Module中,只有在这些懒加载的模块中才会引入这个模块。整个应用程序中需要的其他组件、服务和其他东西(如授权服务或指令、布局组件或服务......)将其放在 App 模块中导入的核心模块中。核心模块(以及应用模块中导入的其他模块)应该尽可能轻量级。

删除这些模块后:

添加自动点模块,

ArchiveModule,

ReservationsModule,

可用性模块

我的app.module.ts解决了延迟加载的问题