如何从child:
localhost/#//config/外设/1000页
to parent
localhost/#/页面/config/外设
我试着:
back(){
this.router.navigate("../", {relativeTo: this.route});
}
在子组件中的,但得到一个重定向到默认站点
我routing.tsconst 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 },
]
}
]
}
];
this.router.navigate("../../out-devices", {relativeTo: this.route});
看起来不像你要从孩子重定向到父母,因为out-devices
和out-devices/:id
都在同一个孩子组
children: [
{ path: 'out-devices', component: ConfigOutDevicesComponent },
{ path: 'out-devices/:id', component: ConfigOutDeviceDetailsComponent },
]
你可以试试,这样子组件更容易重用,因为它以更松散耦合的方式使用重定向。back(){
this.router.navigate("./", {relativeTo: this.route});
}