相关疑难解决方法(0)

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 {}
Run Code Online (Sandbox Code Playgroud)

我想用自己的内部路由导入这个模块,但我想让它的整个路由前缀.

const appRoutes = [
    { path: '', component: HomeComponent },
    /*... (basic routes)*/
];

@NgModule({
    imports: [
        /*...*/
        RouterModule.forRoot(appRoutes),
        CountryModule, // <- how to make its routing prefixed??
    ],
    declarations: [
        /*...*/
        AppComponent,
    ],
    bootstrap: [ AppComponent ]
})
export …
Run Code Online (Sandbox Code Playgroud)

angular2-routing angular2-modules angular

6
推荐指数
2
解决办法
4620
查看次数