I have an angular application where my main routing module lazy loads modules correctly. I do however now have an additional requirement of displaying another component / module inside one of the lazy loaded modules.
When I now navigate to users/id (this part works correctly) I want a tab view in the HTML where I can load additional modules based on what tab is clicked on. For example, I might have 3 buttons: User Albums, User Favourites and User Stats. When I click on one of those, I want a component to display on the same page as a child using the <router-outlet></router-outlet>
App Routing Module
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{ path: 'login', loadChildren: '../app/login/login.module#LoginModule' },
{ path: 'users', loadChildren: '../app/users/users.module#UsersModule' },
{ path: 'users/:id', loadChildren: '../app/user-detail/user-detail.module#UserDetailModule' },
{ path: '', loadChildren: '../app/login/login.module#LoginModule', pathMatch: 'full' },
{ path: '**', loadChildren: '../app/login/login.module#LoginModule', pathMatch: 'full' },
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
user-detail.module
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { UserDetailComponent } from './user-detail.component';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{
path: '',
component: UserDetailComponent,
children: [
{
path: 'useralbums',
loadChildren: '../user-albums/user-albums.module#UserAlbumsModule'
},
]
},
]
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(routes),
],
declarations: [UserDetailComponent]
})
export class UserDetailModule { }
user-detail.html
<h1>User Detail</h1>
<a [routerLink]="['/users', user_id, 'useralbums']">User albums</a>
<a>Link Two</a>
<a>Link Three</a>
<router-outlet></router-outlet>