Angular2 路由器 : Cannot find the outlet XOutlet to load YComponent

标签 angular angular2-routing

我在 Angular2 2.1.2 上使用命名路由器 socket 时遇到问题。

我收到错误:

Cannot find the outlet XOutlet to load 'YComponent'

错误本身很明显,但我卡住了,找不到解决方法。

HTML 看起来像这样:

<router-outlet name="XOutlet"></router-outlet>
<!-- Main content -->
<div class="content-wrapper">
    <router-outlet></router-outlet>
</div>

路由文件:

{
    path: 'other', 
    component: OtherComponent, 
    children: [
        {
            path: 'list',
            component: YComponent,
            outlet: 'XOutlet'
        }
    ]
},

链接

 <a [routerLink]="['other', {outlets: {'XOutlet': 'list'}}]"><span>Other</span></a>

我错过了什么?

谢谢

编辑:根据 Oleg Barinov 的评论,提供的 HTML 是基本 HTML 的一部分,而不是来自 OtherComponent HTML。

最佳答案

使用 <a [routerLink]="['/', {outlets: {'XOutlet': 'list'}}]"><span>Other</span></a>对于这种实现。

关于Angular2 路由器 : Cannot find the outlet XOutlet to load YComponent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40343588/

相关文章:

angular - 如何仅在 Angular 5 中所有子项都已完全加载时才显示页面?

Angular 2 - 测试路由参数的变化

javascript - 带有 Angular 2 : Diasplay my angular 2 component inside dialog using displayDialogAsync 的 DialogAPI

Angular2 - 成功登录后重定向到调用url

angular - 如何从父路由的组件访问已激活的子路由的数据?

json - 如何显示自定义验证错误消息

angular - 如何在 Angular 中使用 mat-text-column

angular - 我可以从 URL 中隐藏 Angular 2 辅助路由吗?

angular - ng-select 服务器端加载图标位置不正确

javascript - Twilio 聊天 API,getUnconsumedMessagesCount 始终为 0