I'm creating a dashboard app and so far I have two lazy loaded modules
AuthModule
and AdminModule
My app-routing-module.ts
looks like this
const routes: Routes = [
{
path: '',
loadChildren: './auth/auth.module#AuthModule'
},
{
path: 'admin',
loadChildren: './admin/admin.module#AdminModule',
canActivate: [AuthGuardService]
},
{
path: '**',
component: NotFoundComponent
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
My app.component.html
has a <router-outlet></router-outlet>
that should render the above routes inside it.
so these urls are working /auth/
and /admin/
perfectly
In my admin-routing.module.ts
I have the following routes
const routes: Routes = [
{
path: '',
component: AdminComponent,
children: [
{path: '', pathMatch: 'full', redirectTo: 'dashboard'},
{path: 'dashboard', component: DashboardComponent },
{path: 'users', component: UsersComponent },
{path: 'reports', component: ReportsComponent },
{path: 'booking', component: BookingComponent }
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
so that /admin/
route directly navigates to /admin/dashboard/
which is also working perfectly.
In my admin.component.html
I added another <router-outlet></router-outlet>
that should renders AdminModule
routes inside it, so I can have a sidenav bar layout.
The problem is that only the default route for AdminModule
which is /admin/dashboard
renders perfectly inside the second router-outlet
whenever I try to navigate to any other child route like /admin/users/
or /admin/booking/
the app redirects to NotFoundComponent