首页 > 解决方案 > 子出口中的角子路线

问题描述

在我的 TestComponent 中,我有一个导航栏,其中包含指向多个组件的链接,我想在 TestComponent 中的子路由器插座中显示这些组件,但它会引发此错误。

core.js:6237 错误错误:未捕获(承诺中):错误:无法匹配任何路由。URL 段:'dashboard/test/id'

const routes: Routes = [
      {
        path: '',
        redirectTo: 'dashboard/test',
        pathMatch: 'full'
      },
      {
        path: 'dashboard',
        children: [
          {
            path: 'test',
            component: TestComponent,
            children: [
              {
                path: '',
                redirectTo: 'id',
                pathMatch: 'full'
              },
              {
                path: 'id',
                component: IdComponent,
                outlet: 'sub'
              }
            ]
          }
        ]
      }
    ];

标签: javascriptangular

解决方案


你的 routerLink 应该是

[routerLink]="['/dashboard/test', {outlets: { sub: ['id'] } }]"


推荐阅读