您可以使用 Angular 路由器 loadChildren 来延迟加载模块。根据用户访问 URL,按需加载其对应的模块。
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
const app_routes: Routes = [
{
path: 'login',
loadChildren: 'app/login/login.module#LoginModule'
},
{
path: 'dashboard',
loadChildren: 'app/dashboard/dashboard.module#DashboardModule'
},
{ path: '', pathMatch: 'full', redirectTo: '/login' },
{ path: '**', pathMatch: 'full', redirectTo: '/login' }
];
@NgModule({
imports: [RouterModule.forRoot(app_routes)],
exports: [RouterModule]
})
export class AppRoutingModule {}