Reputation: 3673
I have following app-routing.module.ts
:
{
path: 'discover',
loadChildren: () => import('./components/platform/user-profile/platform.module').then(m => m.PlatformModule)
},
{
path: ':userRoute',
loadChildren: () => import('./components/platform/user-profile/platform.module').then(m => m.PlatformModule)
},
My goal is that /discover should open DiscoverPageComponent from PlatformModule
/userName1 should open UserPageComponent from PlatformModule
My platform-routing.module.ts
contains following:
{
path: '',
component: UserProfileComponent,
},
{
path: 'discover',
component: DiscoverPageComponent,
},
This doesn't work as /discover will always open the UserProfileComponent instead of the DiscoverPageComponent. I can only open the DiscoverPageComponent from /userName1/discover
How can I have those two different routes open their specific component from the same lazy loaded module?
Stackblitz: https://stackblitz.com/edit/angular-w3rc5g Please see /discover and /anyUserName1
Upvotes: 1
Views: 1694
Reputation: 1003
Try the below sample code, do changes in your routing modules
In app-routing.moudle.ts:
const routes: Routes = [
{
path: '',
loadChildren: () => import('./platform/platform.module').then(m => m.PlatformModule)
},
];
In platform-routing.module.ts:
const routes: Routes = [
{
path: "user",
children: [
{
path: ":user",
component: UserProfileComponent
}
]
},
{
path: "discover",
component: DiscoverComponent
},
{
path: "",
redirectTo: "discover",
pathMatch: "full"
}
];
Upvotes: 1