我想弄清楚如何使@NgModule
更好地组织一个Angular 2模块化应用程序。特别是,我感兴趣的是NgModule 将自己的路径安装到应用程序中。有没有人有一个展示如何去做的工作实例?
答案 0 :(得分:0)
让我们说比较你有家庭模块。
-home
-- home.component.ts
-- home.component.html
-- home.component.spec.ts
-- home.routes.ts
// home.routes.ts
import { Routes, RouterModule } from "@angular/router";
import { HomeComponent } from "./home.component";
const routes : Routes = [
{
path: '',
component: HomeComponent
}
]
export default RouterModule.forChild(routes)
然后在 AppModule 顶级路线:
const routes : Routes = [
{
path: '',
loadChildren: 'app/modules/home/home.module',
pathMatch: 'full'
}
]
@NgModule({
imports: [RouterModule.forRoot(routes)],
export class AppModule {
constructor() {
}
}
这样你的家庭模块就会延迟加载。