Angular:指定路由器插座上的相对导航

Rad*_*FID 5 router-outlet angular angular-router

我有以下Angular Route配置

const appRoutes: Routes = [
    {
      path: '',
      component: DirectoryComponent
    },
    {
      path: 'manage/:type/:id',
      component: ManageComponent,
      outlet: 'manage',
      children: [
        {
          path: '',
          component: PreviewComponent,
          pathMatch: 'full'
        },
        {
          path: 'add/:elementType',
          component: EditComponent,
        }
      ]
    }
  ];
Run Code Online (Sandbox Code Playgroud)

ManageComponent是一个沙箱组件PreviewComponent,EditComponent将在其中呈现.

用户用例重定向http://localhost:4200/#/(manage:manage/bar/12762)与预览组件匹配的用户.一切都还可以.

PreviewComponent当上一个按钮,用户点击,我希望做一个相对导航的EditComponent有,当导航结束,http://localhost:4200/#/(manage:manage/bar/12762/add/foo)

我试过了

this.router.navigate([{outlets: {manage: ['add', 'foo']}}],{relativeTo: this.route});
Run Code Online (Sandbox Code Playgroud)

this.router.navigate([{outlets: {manage: ['add', 'foo']}}]);
Run Code Online (Sandbox Code Playgroud)

但每次,用户都被重定向到http://localhost:4200/#/add/foo.

我该怎么做这个导航?

小智 4

我知道这是一个老问题,但我在寻找答案时找到了解决方案。

您可以使用{ relativeTo: this.activatedRoute.parent },一切都像魅力一样。