angular - Angular 2+父/子路由
问题描述
我设置了这两条路线
{ path: 'manage-brands', component: ManageBrandsComponent, canActivate: [AuthGuard] },
{ path: 'manage-brand/:brandId', component: BrandAdminComponent },
但我真正想要的是:/manage-brands -> ManageBrandsComponent 然后在路由 /manage-brands/brandId -> BrandAdminComponent 中是否应该有一个 id
有没有办法使用 children: [ ] 来实现这一点,还是我必须只使用一个组件来呈现基于 RouteSnapshot 的 ng 模板?
解决方案
这是实现此行为的父子方式。
const routes: Routes = [
{
path: 'manage-brands', component: ManageBrandsComponent,
canActivate: [AuthGuard],
children: [
{ path: ':brandId', component: BrandAdminComponent }
]
}
]
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
推荐阅读
- python - 如何在 Python 中找到 txt 文件中列的平均值?
- c# - 如何在 C# 中通过循环以编程方式创建 TabControl 并通过 TabPages 填充它?
- amazon-web-services - Can i use wildcards to define a resource in an AWS IAM role?
- c++ - Xcode can't find libraries - 'cppunit/TestResultCollector.h' file not found
- python - 来自 Python 应用程序的 Outlook 电子邮件文本格式
- jmeter - 在 JMeter 中断言整个测试计划的持续时间
- laravel - 极慢的推荐引擎
- contiki - 节点周围的双红圈是什么意思?
- docker - 与服务器 rancher.xxx.xxx 的连接被拒绝 - 您是否指定了正确的主机或端口?
- html - 如何在 NodeJs express 应用程序中使用的 HTML 模板中动态更改样式的“宽度”