Angular 角度2从子对象导航到父对象
如何从子级导航: localhost/#/pages/config/out devices/1000 给父母 localhost/#/pages/config/out设备 我试过:Angular 角度2从子对象导航到父对象,angular,angular2-routing,Angular,Angular2 Routing,如何从子级导航: localhost/#/pages/config/out devices/1000 给父母 localhost/#/pages/config/out设备 我试过: back(){ this.router.navigate("../", {relativeTo: this.route}); } 在子组件中,但获得到默认站点的重定向 我的旅行路线 const routes: Routes = [ { path: 'login', component: LoginC
back(){
this.router.navigate("../", {relativeTo: this.route});
}
在子组件中,但获得到默认站点的重定向
我的旅行路线
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 },
]
}
]
}
];
看起来您不会从子设备重定向到父设备,因为
out设备
和out设备/:id
都在同一个子组中
children: [
{ path: 'out-devices', component: ConfigOutDevicesComponent },
{ path: 'out-devices/:id', component: ConfigOutDeviceDetailsComponent },
]
您可以尝试,这样子组件更具可重用性,因为它以更松散耦合的方式使用重定向
父路由的外观如何?我添加了我的routin.ts文件什么组件包含
back()
方法?ConfigOutDeviceDetailsComponentM重定向到localhost/#/pages/devicesAddpathMatch:'full'
到`{path:'',重定向到:'devices'},。所有路径为空且没有子路径的路由都应具有
pathMatch:'full'`thx当我将[]添加到路径this.router.navigate([“../../out devices”],{relativeTo:this.route})时,它会起作用代码>我明白了,错过了那个。
children: [
{ path: 'out-devices', component: ConfigOutDevicesComponent },
{ path: 'out-devices/:id', component: ConfigOutDeviceDetailsComponent },
]
back(){
this.router.navigate("./", {relativeTo: this.route});
}