Angular 2从子级导航到父级 [英] Angular 2 navigate from child to parent

查看:68
本文介绍了Angular 2从子级导航到父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从孩子那里导航:

How can i navigate from child:

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

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

给父母

localhost/#/pages/config/out-devices

localhost/#/pages/config/out-devices

我尝试过:

back(){
    this.router.navigate("../", {relativeTo: this.route});
}

在子组件中,但重定向到默认站点

in the child Component but get a redirection to default site

我的routing.ts

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 },

                ]
            }

        ]
    }
];

推荐答案

this.router.navigate("../../out-devices", {relativeTo: this.route});

这篇关于Angular 2从子级导航到父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆