【问题标题】:Angular: How to navigate to child route from parent component by using navigate methodAngular:如何使用导航方法从父组件导航到子路由
【发布时间】:2019-12-19 18:05:17
【问题描述】:

这是我的html rouerLink:

<a [routerLink]="['create']">Create</a> - 工作正常。

点击按钮时我的调用方式与:但不起作用..

navigateTo(page) {
        this.router.navigate(['create']); //not works
    }

任何人帮助我,我在这里真正缺少什么?

更新

我正在从父母导航到孩子

路线如下:

{
                path: 'contentPlaceholder',
                data: { showNavi: true },
                component: ShellContentPlaceholderComponent,

                children : [
                    {
                        path: 'view',
                        data: { showNavi: false },
                        component: ShellContentViewPlaceholderComponent,
                    },
                    {
                        path: 'create',
                        data: { showNavi: false },
                        component: ShellContentCreatePlaceholderComponent,
                    },
                    {
                        path: 'edit',
                        data: { showNavi: false },
                        component: ShellContentEditPlaceholderComponent,
                    },
                    {
                        path: 'update',
                        data: { showNavi: false },
                        component: ShellContentUpdatePlaceholderComponent,
                    }
                ]
            }

【问题讨论】:

  • @PrashantPimpale - 我在contentPlaceholder

标签: angular angular-router angular8


【解决方案1】:

尝试将relativeTo 值设置为当前路由:

constructor(private router: Router, private route: ActivatedRoute) {}

然后:

this.router.navigate(['./create'], { relativeTo: this.route });

【讨论】:

    猜你喜欢
    • 2023-04-06
    • 2019-07-27
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-28
    • 2020-01-04
    • 2019-07-28
    相关资源
    最近更新 更多