{ "compilerOptions": { "esModuleInterop": true, //其他选项 } }
import { NgModule } from '@angular/core'; import { RouterModule } from '@angular/router'; import { CommonModule } from '@angular/common'; import { LazyLoadedModule } from './lazy-loaded-module';
@NgModule({ imports: [ CommonModule, RouterModule.forChild([{ path: '', component: LazyLoadedModule }]) ], declarations: [ //组件和指令 ] }) export class HomeModule {}
import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [ { path: '', loadChildren: () => import('./home/home.module').then(m => m.HomeModule) //这是一个懒加载模块 }, //其他路由 ];
@NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] }) export class AppRoutingModule { }
通过以上步骤,你就可以创建代码块并正确地进行懒加载了。