I have the following scenario. I have two components, InvLoginComponent and InvDashboardComponent that are mounted on the "primary" (or nameless) router in my application. The user logs in and is routed to the dashboard component. Inside the dashboard, I have a sidenav with links. When the links are clicked, I want to load the related component(s) inside a named router outlet inside InvDashSidenavComponent which, is nested in InvDashboardComponent. So far, the code looks like this:
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>
When I run the app, the following happens:
1. The dashboard and all other non-sidenav components are loaded as before.
2. Upon triggering the sidenav from a toggle button, the sidenav slides in as usual.
3. When the link are clicked, I receive the following error message: Error: Cannot match any routes. URL Segment: 'dashboard'.
What's causing this error and what are the ways to fix this?
[{ outlets: {casesOutlet:[c.href] } }]you should place[routerLink]="c.href"- Християн ХристовError: Cannot match any routes. URL Segment: 'dashboard/pending- Abrar Hossain