我有两条主要路线,都加载相同的子模块。有没有任何可能的方法在子模块上有两个同名的路由,该子模块相对于主路由加载两个不同的组件。
主要路线:
export const ROUTES: Routes = [{
path: 'first',
loadChildren: './features/common#CommonModule',
canActivate: [AppAuthGuard]
}, {
path: 'second',
loadChildren: './features/common#CommonModule',
canActivate: [AppAuthGuard]
}]
现在我希望通用模块有这样的路由
export const routes = [{
path: 'list', component: FirstListComponent, pathMatch: 'full' }
},{
path: 'list', component: SecondListComponent, pathMatch: 'full' }
}]
所以,我想要类似的东西
- 如果路由是first/list,那么应该加载FirstListComponent。
- 如果路由是second/list,则应加载SecondListComponent。
我知道路线的顺序很重要。而且建议的方式是不可能的。任何人都可以提出任何可能的方法来实现这一目标。
最佳答案
请这样设置路径
export const routes = [{
path: 'first/list', component: FirstListComponent, pathMatch: 'full' }
},{
path: 'second/list', component: SecondListComponent, pathMatch: 'full' }
}]
关于Angular 2不同模块相同的路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46663700/