0
Hello, I’m working with Angular 2(v4+), where my application has the following structure containing 2 modules that are dynamically loaded (via loadChildren
):
Directory structure
app
|-foo
| |- foo.module
| |- ... (foo components)
|-bar
| |- bar.module
| |- ... (bar components)
Approuting.ts
export const AppRoutes: Routes = [
{ path: '', loadChildren: './foo/foo.module#FooModule' },
{ path: 'bar', loadChildren: './bar/bar.module#BarModule' }
];
Foorouting.ts
export const FooRoutes: Routes = [
{ path: '', component: ManageComponent },
{ path: ':id', component: DetailsComponent },
{ path: 'list', component: ListComponent },
{ path: '**', component: FooErrorNotFoundComponent }
];
Barrouting.ts
export const BarRoutes: Routes = [
{ path: '', component: WorkspaceComponent },
{ path: 'view', component: ViewComponent },
{ path: 'another', component: AnotherComponent },
];
My problem is this:
- I need each sub-module to have its own error screen, because its sub-components can change as navigation bars, etc...
- When I use the above structure and try to access the url
localhost:300/bar/view
Angular is directing me to the Foo error page, meaning he’s not initially respecting the Approuting routes and going straight to Foo. - If I remove the Foo error page, then Angular directs me to the Bar submodule.
How can I keep the Foo module error page but forcing Angular to respect the initial App routing structure?