[英]How to hide the parent component when loading a child component in Angular 2
在我当前的项目中,我有以下观点
当页面加载时, Parent Item Description
应该可见,而Selected sub item description
应该不可见。
当我选择一个Sub Item x
, Parent Item Description
应该被隐藏,只有Selected sub item description
可见。
我为此创建了以下路线
{
path: 'main/:id',
component: MainComponent,
children: [
{
path: '',
component: MainComponent,
pathMatch: 'full',
},
{
path: 'sub/:id',
component: SubComponent
}
]
},
但是当运行该项目时,它并没有像我期望的那样工作。
我添加了一个<router-outlet></router-outlet>
来加载子项描述,但是当我转到主项时,主项本身复制到该router-outlet
。
总之,我希望仅在右侧加载所选项目的描述。
您需要将父路由转换为无组件路由,如下所示:
{
path: 'main/:id',
children: [
{
path: '',
pathMatch: 'full'
component: MainComponent,
},
{
path: 'sub/:id',
component: SubComponent
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.