[英]Navigation between two Angular children routes
I have the following routes: 我有以下路线:
const appRoutes: Routes = [
{
outlet: 'primary',
path: '',
children: [
{
path: 'briefs',
children: [
{
path: '',
outlet: 'menu',
component: BrieflistMenuComponent
},
{
path: '',
outlet: 'main',
component: BrieflistComponent
}
]
},
{
path: 'brief/:id',
children: [
{
path: '',
outlet: 'menu',
component: BriefMenuComponent
},
{
path: '',
outlet: 'main',
component: BriefComponent
}
]
},
{
path: '**',
redirectTo: '/briefs',
pathMatch: 'full'
}
]
}
];
How can I navigate between briefs/
and brief/XXX/
using this.router.navigate(...)
? 如何使用
this.router.navigate(...)
在briefs/
和briefs/
brief/XXX/
之间导航? I tried this.router.navigate(['brief', id]);
我尝试过
this.router.navigate(['brief', id]);
but I get the following error: Error: Cannot activate an already activated outlet Error: Cannot activate an already activated outlet
. 但是出现以下错误:
Error: Cannot activate an already activated outlet Error: Cannot activate an already activated outlet
。
How to redirect all undefined paths to briefs/
? 如何将所有未定义的路径重定向到
briefs/
?
I use Angular 5. 我使用Angular 5。
I finally found out by myself. 我终于自己找到了。 For the first question, one of the two outlets should not be named.
对于第一个问题,不应指定两个出口中的一个。 For the second question, I added
{ path: '**', redirectTo: '/briefs', pathMatch: 'full' }
to the children of the main ''
path. 对于第二个问题,我在主
''
路径的子级中添加了{ path: '**', redirectTo: '/briefs', pathMatch: 'full' }
。
const appRoutes: Routes = [
{
outlet: 'primary',
path: '',
children: [
{
path: 'briefs',
children: [
{
path: '',
outlet: 'menu',
component: BrieflistMenuComponent
},
{
path: '',
// outlet: 'main',
component: BrieflistComponent
}
]
},
{
path: 'brief/:id',
children: [
{
path: '',
outlet: 'menu',
component: BriefMenuComponent
},
{
path: '',
// outlet: 'main',
component: BriefComponent
}
]
},
{
path: '**',
redirectTo: '/briefs',
pathMatch: 'full'
}
]
}
];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.