我试图导航到一个嵌套的辅助路由,但是一直出现错误:
ERROR Error: Uncaught (in promise):
Error: Cannot match any routes. URL Segment: 'sign-in'
我试图导航到的URL:
http://localhost:4200/(modalcontainer:modals//modalview:sign-in)
我的路由器配置如下:
对于这条路线,我的路由器配置如下:
{
path: 'modals',
component: ModalsComponent,
outlet: 'modalcontainer',
children: [
{
path: 'register',
outlet: 'modalview',
component: ModalRegisterComponent
},
{
path: 'sign-in',
outlet: 'modalview',
component: ModalSigninComponent
}
]
}
因此,有两个router-outlets
,分别是modalcontainer
和modalview
。后者位于ModalsComponent
的模板内。
AppComponent
<router-outlet></router-outlet>
<router-outlet name="modalcontainer"></router-outlet>
模态框组件
<div class="overlay" (click)="close($event)">
<router-outlet name="modalview"></router-outlet>
</div>
modalcontainer
弹出正常,但在尝试弹出 modalview
时出错。
我尝试过的导航方式有:
[routerLink]="[{outlets: {'modalcontainer': ['modals'], 'modalview': ['register']}}]"
[routerLink]="[{outlets: {'modalcontainer': ['modals'], 'modalview': ['modals', 'register']}}]"
[routerLink]="['modals', {outlets: {'modalview': ['register']}}]"
- 直接在地址栏中输入
http://localhost:4200/(modals:modals//modal:sign-in)
this.router.navigate([{outlets: {'modalcontainer': ['modals'], 'modalview': ['register']}}]);
this.router.navigateByUrl('/(modals:modals//modal:sign-in)');
是我的配置或访问URL的方式有问题吗?还是这是一个 bug?
http://localhost:4200/(modalcontainer:modals/(modalview:sign-in))
。 - thorn0