我有以下情况。我有两个组件,InvLoginComponent
它们InvDashboardComponent
安装在我的应用程序中的“主要”(或无名)路由器上。用户登录并被路由到仪表板组件。在仪表板内部,我有一个带有链接的 sidenav。单击链接时,我想将相关组件加载到一个命名的路由器出口内InvDashSidenavComponent
,其中嵌套在InvDashboardComponent
. 到目前为止,代码如下所示:
app.module.ts
// Routes
const routes: Routes = [
{path: "", redirectTo: "login", pathMatch: "full"},
{path: "login", component: InvestigatorLoginComponent },
{path: "dashboard", component: InvDashboardComponent },
{path: "pending", component: PendingCasesComponent, outlet:'casesOutlet' },
{path: "completed", component: CompletedCasesComponent, outlet: 'casesOutlet'},
{path: "flagged", component: FlaggedCasesComponent, outlet: 'casesOutlet' }
];
// ... in imports
RouterModule.forRoot(
routes, { enableTracing: false} // <= debugging
),
// ... rest of app.module.ts
app.component.ts
<router-outlet
(activate)="activateHandler($event)"
(deactivate)="deactivateHandler($event)"
></router-outlet> <!-- Nameless or primary outlet -->
inv-dash-sidenav.component.ts
caseRoutes = [
{ name: 'Pending', href: 'pending' },
{ name: 'Completed', href: 'completed' },
{ name: 'Review', href: 'review' },
{ name: 'Flagged', href: 'flagged' }
]; // used in the template for binding to routerLink
inv-dash-sidenav.component.html
<mat-nav-list *ngIf="showCases">
<a mat-list-item *ngFor="let c of caseRoutes">
<a [routerLink]="[{ outlets: {casesOutlet:[c.href] } }]" routerLinkActive="active">{{ c.name }}</a>
</a>
</mat-nav-list>
<!-- Later in the template -->
<router-outlet name="casesOutlet"></router-outlet>
当我运行该应用程序时,会发生以下情况: 1. 仪表板和所有其他非 sidenav 组件都像以前一样加载。2. 从切换按钮触发 sidenav 后,sidenav 像往常一样滑入。3. 点击链接时,我收到以下错误信息:Error: Cannot match any routes. URL Segment: 'dashboard'
。
是什么导致了这个错误,有什么方法可以解决这个问题?