In my Angular 13 application, I have implemented routes that lead to various modules with their own set of child routes.
The routing configuration for each module looks like this:
@NgModule({
declarations: [DashboardComponent],
imports: [RouterModule.forChild(childRoutes)]})
export class ChildModule{}
export const childRoutes = [
{path: 'dashboard', component: DashboardComponent},
{path: 'reports', component: ReportsComponent}];
Within the parent module, the child module is lazy loaded using the following setup:
export const appRoutes = [
{path: 'store', component: StoreLayoutComponent,
loadChildren: () => import('app/store/child.module').then(m => m.ChildModule)}];
@NgModule({
imports: [
...
RouterModule.forRoot(appRoutes)
],
...})
export class AppModule {}
Surprisingly, both URLs
https://localhost:4200/store/dashboard
and
https://localhost:4200/dashboard
successfully load the DashboardComponent
.
This behavior raises a question - why does the second URL work when it shouldn't be valid?