我有一个主模块和一些子模块。我想在它们之间指定一些不重要的路由。Angular2路由:使用路由导入子模块+使其前缀
我宁愿在子模块内定义子模块的路由。例如: -
@NgModule({
imports: [
/*...*/
RouterModule.forChild([
{ path: 'country', redirectTo: 'country/list' },
{ path: 'country/list', component: CountryListComponent },
{ path: 'country/create', component: CountryCreateComponent },
/*...*/
])
],
declarations: [/*...*/],
exports: [
RouterModule,
],
})
export class CountryModule {}
我想导入该模块有自己的内部路由,但我想使其整个路由前缀。
const appRoutes = [
{ path: '', component: HomeComponent },
/*... (basic routes)*/
];
@NgModule({
imports: [
/*...*/
RouterModule.forRoot(appRoutes),
CountryModule, // <- how to make its routing prefixed??
],
declarations: [
/*...*/
AppComponent,
],
bootstrap: [ AppComponent ]
})
export class AppModule {}
此设置创建下列路线:3210,/country/list
等,但我想让他们前缀是这样的:
/settings/country
/settings/country/list
/settings/country/create
还有其他模块我想通过其他路由访问的文件,例如CityModule
在/otherstuff/city/create
和/ otherstuff/city/list`下。
我的问题:
- 是否可以导入一个模块都以其自身的路由,并使其路线前缀?
- 此外:有没有办法在两个子模块之间建立最终(前缀)路线的无关联?
UPDATE
接受的答案是做到这一点的最好办法:该模块中创建的路由,外部注册。因此,你可以修改路线,例如它们的前缀(这是我想要的),你可以定义卫士,重写或过滤等
对不起。下面是一个问题:http://stackoverflow.com/questions/39131350/nesting-angular2-rc5-routes-multiple-files –