角度辅助路线 - 无法在同一导航调用中导航和清除辅助路线?



我遇到了一个问题,看来我无法导航到新路线,并同时清除出口/次要路线。

称这两个动作分别起作用 - 但感觉就像是解决方法。是否有充分的理由将它们作为两个电话进行?还是我的实施中存在错误?还是我应该将其作为GitHub问题提交?

这些独立工作:

// Navigate to `/second`
this._router.navigate(['/second']);
// Clears the `popup` outlet
this._router.navigate(['', {outlets: { popup: null }}]);

我认为这应该有效,但没有清楚的出口:

this._router.navigate(['/second', {outlets: { popup: null }}]);

我目前的工作是:

this._router.navigate(['', {outlets: { popup: null }}]).then(() => { this._router.navigate(['second']); } );

我已经创建了PLNKR概念验证 - 导航代码在global-popup.component.ts

您需要明确设置主路径,如下所示,

public closeAndNav_singleCall() {
   return this._router.navigate([{
     outlets: { 
       primary : ['second'],
       popup: null 
     }
   }]);
}

更新了您的Plunker !!

希望这会有所帮助!

当主要导航在主路线上绝对是绝对的时,上面有效。我遇到的问题是:如何在主要路线上进行相对导航,同时清除辅助路线。

我尝试了不同的组合,但似乎没有用:

https://localhost:4200/one/two(popup:some/other)

    this.router.navigate([
      '',
      {
        outlets: {
          primary: ['areaTwo', 'second'],
          popup: null,
        },
      },
    ]);

结束在https://localhost:4200/areaTwo/second

因此,它清除了次要弹出窗口,并且可以执行绝对的导航。

https://localhost:4200/one/two(popup:some/other)

    this.router.navigate([
      {
        outlets: {
          primary: ['areaTwo', 'second'],
          popup: null,
        },
      },
    ], { relativeTo: this.activatedRoute });

https://localhost:4200/one/two/areaTwo/second(popup:some/other)

结束

因此,它在初级上做亲戚,但无法清除次级。

但是我们如何做类似的事情:

https://localhost:4200/one/two(popup:some/other)

结束在https://localhost:4200/one/two/areaTwo/second

最新更新