I have a ProfileModule with the following routing :
// profile-routing.module
const routes: Routes = [
{
path: ':id',
component: ProfilePageComponent,
children: [
{
path: '',
redirectTo: 'feed',
pathMatch: 'full'
},
{
path: 'feed',
component: NewsFeedComponent
},
{
path: 'gallery',
component: MediasGalleryComponent
}
]
}
];
It works as follow:
ProfilePageComponentfetches the profile ID in routing parameters and sends it to aProfilePageServiceNewsFeedComponentandMediasGalleryComponentreceive the profile ID fromProfilePageService
Now, these two pages have been moved into two separate modules (respectively NewsModule and MediasModule), that I want to be lazy loaded in this routing. I cannot use ProfilePageService anymore. I came up with this solution :
// profile-routing.module
const routes: Routes = [
{
path: ':id',
component: ProfilePageComponent,
children: [
{
path: '',
redirectTo: 'news/:id/feed', // same as the parent ID
pathMatch: 'full'
},
{
path: 'news',
loadChildren: () => import('./news/news.module').then(m => m.NewsModule)
},
{
path: 'medias',
loadChildren: () => import('./medias/medias.module').then(m => m.MediasModule)
}
]
}
];
// news-routing.module
const routes: Routes = [{
path: ':profileId/feed',
component: NewsFeedComponent
}];
// medias-routing.module
const routes: Routes = [{
path: ':profileId/gallery',
component: MediasGalleryComponent
}];
This solution is not working, since I cannot get the profile ID parameter from parent route. How can I avoid this problem ?
Moreover, I don't like the fact that profile ID is duplicated in the URL. What would be the Angular way to do things ?