Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度2从子对象导航到父对象_Angular_Angular2 Routing - Fatal编程技术网

Angular 角度2从子对象导航到父对象

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

如何从子级导航:

localhost/#/pages/config/out devices/1000

给父母

localhost/#/pages/config/out设备

我试过:

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/devicesAdd
pathMatch:'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});
}