I'm facing challenges with handling 404 pages within an Angular 10 application that utilizes modular routing architecture.
Here is the structure of my code:
|> app
|-- app.module.ts
|-- app-routing.module.ts
|-- app.component{ts, spec.ts, scss, html}
|-> pages
|--- pages.module.ts
|--> home-page
|---- home-page.module.ts
|---- home-page-routing.module.ts
|---> home-page
|----- home-page.component{ts, spec.ts, scss, html}
|--> test-page
|---- test-page.module.ts
|---- test-page-routing.module.ts
|---> test-page
|----- test-page.component{ts, spec.ts, scss, html}
The global app-routing module has a 404 handler configured as seen below:
...
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
const routes: Routes = [
{ path: '', redirectTo: '/home', pathMatch: 'full' },
// If the following line is not commented out,
// You are unable to navigate to either the 'Home' or 'Test' pages.
// { path: '**', component: PageNotFoundComponent },
];
...
The issue I am encountering is that Angular resolves to the global 404 handler in ./app/app-routing.module.ts
instead of the intended page route.
I have provided a sample StackBlitz showcasing this behavior (Note: The StackBlitz example is running Ng12, but our app is using Ng10 with similar behavior)
My objective is to implement a global 404 handler or redirection functionality while maintaining separate definitions for page routes within their respective module-routing files.
Is it possible to achieve this, and if so, how?