[英]NgModule installing its own routes
I am trying to figure out how to empoy @NgModule
to better organize an Angular 2 modular app. 我试图找出如何empoy
@NgModule
更好地组织一个角2模块化的应用程序。 In particular, I am interested in an NgModule installing its own routes into the app. 特别是,我对NgModule 将自己的路由安装到应用程序中感兴趣。 Does anyone have a working example showing how to go about it?
有没有人有一个可行的例子来说明如何去做?
Let's say for example you have the home module. 假设您有home模块。
-home
-- home.component.ts
-- home.component.html
-- home.component.spec.ts
-- home.routes.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)
Then in your AppModule top level routes: 然后在您的AppModule顶级路线中:
const routes : Routes = [
{
path: '',
loadChildren: 'app/modules/home/home.module',
pathMatch: 'full'
}
]
@NgModule({
imports: [RouterModule.forRoot(routes)],
export class AppModule {
constructor() {
}
}
With this your home module will be lazy loading. 有了这个,你的家庭模块将被延迟加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.