如何将孙视图渲染到与第一个孩子相同的路由器插座中? [英] How to render a grandchild view into the same router-outlet as the first child?
问题描述
这是一个后续问题:Angular 2辅助路由在 2.1.0 中是如何工作的?
我也试过看这个,但它并没有真正说明这个问题:如何将子路由渲染到父节点的router-outlet
I also tried looking at this but it doesn't really shed any light on the issue: How to render the child route into the router-outlet of the parent`s parent
如果我有一个父路由 /admin
它有一个
看起来像这个:
If I have a parent route /admin
which has a <router-outlet name="admin"></router-outlet>
which looks like this:
const routes: Routes = [
{
path: '',
component: AdminAreaComponent,
canActivate: [AuthGuardService]
},
{
path: 'login',
loadChildren: '../pages/+login/login.module#LoginModule',
outlet: 'admin'
},
{
path: 'dashboard',
loadChildren: '../pages/+dashboard/dashboard.module#DashboardModule',
outlet: 'admin'
}
];
我将通过 /admin(admin:dashboard)
访问仪表板,但现在我需要将 dashboard
的子视图渲染到同一个 router-outlet
作为仪表板,即 admin
.该视图如下所示:
I would access the dashboard via /admin(admin:dashboard)
, but now I need to render a child view of dashboard
into the same router-outlet
as the dashboard, which is admin
. That view looks like this:
const routes: Routes = [
{
path: '',
component: DashboardComponent
},
{
path: 'brands',
loadChildren: '../pages/+brands/brands.module#BrandsModule',
outlet: 'admin'
}
];
但是,当我尝试通过 /admin(admin:dashboard/brands)
访问此路线时,出现错误:
However, when I try to access this route via /admin(admin:dashboard/brands)
I get an error:
Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'admin'
我猜我在路由配置中做错了什么.
I'm guessing that I'm doing something wrong in the route config.
我该如何解决这个问题?
How can I fix this?
推荐答案
这听起来很疯狂,但为什么不让 dashboard
成为 admin
的子模块?
This might sound crazy, but why not make dashboard
a child module of admin
?
这篇关于如何将孙视图渲染到与第一个孩子相同的路由器插座中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!