Since I heard Angular, the router supports nested <router-outlet> tags, I am trying to use two of them. I use the latest Angular -CLI, converting from ui-router to Angular Router. I canβt get a second router to populate the contents.
(Parent routing is working fine) application-routing.module.ts
...
const routes: Routes = [
{ path: '', pathMatch: 'full', component: LoginComponent },
{ path: 'login', pathMatch: 'full', component: LoginComponent },
{ path: 'dashboard',
pathMatch: 'full',
component: DashboardComponent
},
{ path: '**', component: LoginComponent }
];
@NgModule({
imports: [
RouterModule.forRoot(routes)
],
exports: [ RouterModule ]
})
export class AppRoutingModule { }
app.component.ts - it just keeps the router exiting and works great at the top level ...
<router-outlet></router-outlet>
The dashboard stores universal headers, footers, sidebars, etc. Therefore, I want it to be on a top-level router. Sub-router-outlet will populate child views, but will not populate.
Attempt 1 dashboard-routing.module.ts
export const dashboardRoutes: Routes = [
{ path: '', pathMatch: 'full', redirectTo: 'home' },
{ path: 'home', pathMatch: 'full', component: HomeComponent },
{ path: 'about', pathMatch: 'full', component: AboutComponent }
]
@NgModule({
imports: [
RouterModule.forChild(dashboardRoutes)
],
exports: [ RouterModule ]
})
export class DashboardRoutingModule { }
2 -routing.module.ts Angular2: - -
export const dashboardRoutes: Routes = [
{
path: 'dashboard',
children:[
{ path: '', component: DashboardComponent},
{ path: 'home', component: HomeComponent},
{ path: 'about', component: AboutComponent}
]
}
]
@NgModule({
imports: [
RouterModule.forChild(dashboardRoutes)
],
exports: [ RouterModule ]
})
export class DashboardRoutingModule { }
Dashboard - . app.component.html: (
dashboard.component.html
<header>...</header>
<aside class="sidenav">...<aside>
<router-outlet></router-outlet>
************** , PierreDuc! **************
-routing.module.ts
const routes: Routes = [
{ path: '', pathMatch: 'full', component: LoginComponent },
{ path: 'login', pathMatch: 'full', component: LoginComponent },
{ path: '**', component: LoginComponent }
];
@NgModule({
imports: [
RouterModule.forRoot(routes),
DashboardRoutingModule
],
exports: [ RouterModule ]
})
export class AppRoutingModule { }
-routing.module.ts
export const dashboardRoutes: Routes = [
{
path: 'dashboard',
component: DashboardComponent,
children:[
{ path: '', component: HomeComponent },
{ path: 'home', pathMatch: 'full', component: HomeComponent },
{ path: 'about', pathMatch: 'full', component: AboutComponent }
]
}
]
@NgModule({
imports: [
RouterModule.forChild(dashboardRoutes)
],
exports: [ RouterModule ]
})
export class DashboardRoutingModule { }
, :
login.component.ts
... passed validation ...
this._router.navigate(['/dashboard']);
this._router.navigate(['/dashboard/home']);
routerLink
dashboard.component.html
[routerLink]="['../login']" <!-- back to login, though the '../' seems less than ideal
routerLink -:
dashboard.component.html:
[routerLink]="['../about']"