I'm trying to have multiple angular routes for a child component and I must use lazy loading (loadChildren).
- /page1/from1 -> MyComponent
- /page2/from2 -> MyComponent
- /page1/from2 -> no match
- /page2/from1 -> no match
As we can see, /page1/from1 and /page2/from2 should show show MyComponent, but /page1/from2 must not route to MyComponent.
Here's what I've tried:
The app routing:
const routes: Routes = [
{ path: 'page1', loadChildren: () => import(`./MyComponentModule.module`).then(x => x.MyComponentModule) },
{ path: 'page2', loadChildren: () => import(`./MyComponentModule.module`).then(x => x.MyComponentModule) }
];
The component module routing:
const routes: Routes = [
{ path: 'from1', component: MyComponentModule },
{ path: 'from2', component: MyComponentModule }
];
The problem with this solution
This matches /page1/from2 as well as /page2/from1, which is not what I need. Is there an elegant way to do this?