本文介绍了在保留主要路线的同时导航到辅助路线的角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想导航到称为模态的辅助路线,而无需明确说明主要路线.
I would like to navigate to a secondary route called modal without explicitly stating the primary route.
我已经在组件类中尝试过:
I've tried this in the component class:
onclick(){
this.router.navigate([{ outlets: { foo: 'modal' } }], { relativeTo: this.route });
}
上面的代码似乎有效.但是,它导航到/first(foo:modal)
一秒钟,然后导航到根/
.
The above code seems to work. However, it navigates to /first(foo:modal)
for a split second then it navigates to the root /
.
我做错了什么?
做类似的事情会很好:
<a href="#" routerLink="/*(foo:modal)">Open Modal</a>
以便它与任何主要路线匹配....这可能吗?
So that it matches any primary route.... Is this possible?
推荐答案
您只能通过指定出口{ oultletName: url}
<a [routerLink]="[{outlets: { modal: 'edit/20']}}]">Edit</a>
router.navigate([{outlets: { modal: 'edit/20'}}]);
或多个细分:
<a [routerLink]="[{outlets: {primary: 'products', modal: 'edit/20']}}]">Edit</a>
router.navigate([{outlets: {primary: 'products', modal: 'edit/20'}}]);
这篇关于在保留主要路线的同时导航到辅助路线的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!