我如何从儿童导航:
本地主机/#/页/配置/出装置/ 1000
到父母
本地主机/#/页/配置/外设备
我试过了:
back(){
this.router.navigate("../", {relativeTo: this.route});
}
在子Component中,但获得重定向到默认站点
my routing.ts
const routes: Routes = [
{ path: 'login', component: LoginComponent},
{ path: '', redirectTo: 'login', pathMatch: 'full' },
{
path: 'pages',
canActivate: [AuthGuard],
component: PagesComponent,
children: [
{ path: '', redirectTo: 'devices'},
{ path: 'devices', component: DevicesComponent },
{ path: 'groups', component: GroupsComponent },
{
path: 'config',
component: ConfigComponent,
children: [
// general
{ path: 'out-devices', component: ConfigOutDevicesComponent },
{ path: 'out-devices/:id', component: ConfigOutDeviceDetailsComponent },
]
}
]
}
];
答案 0 :(得分:3)
this.router.navigate("../../out-devices", {relativeTo: this.route});
答案 1 :(得分:0)
看起来您不会将孩子重定向到父母,因为out-devices
和out-devices/:id
都属于同一子组
children: [
{ path: 'out-devices', component: ConfigOutDevicesComponent },
{ path: 'out-devices/:id', component: ConfigOutDeviceDetailsComponent },
]
您可以尝试,这样子组件可以更加重复使用,因为它使用更多松散耦合方式的重定向。
back(){
this.router.navigate("./", {relativeTo: this.route});
}