0
votes

Cant seem to find what the issue is here as I'm getting no errors from Angular.

I am trying to get a router-outlet inside the primary router-outlet to display a component. Im correctly selecting the router but it is not showing the component i have selected in the second outlet.

app-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';


const routes: Routes = [
    { path: 'dashboard', loadChildren: () => import('./pages/dashboard/dashboard.module').then(m => m.DashboardModule) }
];

@NgModule({
    imports: [RouterModule.forRoot(routes)],
    exports: [RouterModule]
})
export class AppRoutingModule { }

dashboard-routing.module.ts

// ...

const routes: Routes = [
    { path: '', component: DashboardComponent },
    { path: 'forms', component: FormsComponent, outlet: 'sidebar' },
];

@NgModule({
    imports: [RouterModule.forChild(routes)],
    exports: [RouterModule]
})
export class DashboardRoutingModule { }

dashboard.component.html

<app-header></app-header>

<mat-sidenav-container>
    <mat-sidenav mode="side" opened>
        <mat-nav-list>
            <a mat-list-item [routerLink]="[{ outlets: { sidebar: ['forms'] } }]" routerLinkActive="active">Forms</a>
        </mat-nav-list>
    </mat-sidenav>
    <mat-sidenav-content>
        <main class="bfa-main">
            <router-outlet name="sidebar"></router-outlet>
        </main>
    </mat-sidenav-content>
</mat-sidenav-container>

<app-footer></app-footer>

The routerlink is correctly selected and displays an active class, as well as a link too:

http://localhost:4200/dashboard/(sidebar:forms)

However there is nothing displayed here and no errors, when i am expecting to see the forms component inside the inner router outlet named sidebar

Does anyone know what I'm missing here?

Thanks

1

1 Answers

0
votes

Decided to have the dashboard as a wrapper instead for each of the dashboard components using ng-content

<app-header></app-header>

<mat-sidenav-container>
    <mat-sidenav mode="side" opened>
        <mat-nav-list>
            <a mat-list-item [routerLink]="['forms']" routerLinkActive="active">Forms</a>
            <a mat-list-item [routerLink]="['users']" routerLinkActive="active">Users</a>
            <a mat-list-item [routerLink]="['posts']" routerLinkActive="active">Posts</a>
            <a mat-list-item [routerLink]="['pages']" routerLinkActive="active">Pages</a>
        </mat-nav-list>
    </mat-sidenav>
    <mat-sidenav-content>
        <main class="bfa-main">
            <ng-content></ng-content>
        </main>
    </mat-sidenav-content>
</mat-sidenav-container>

<app-footer></app-footer>