I have a pretty big project and in order to reduce bundle size i decided to divide it into multiple modules with lazy load. and here is my app-routing
const routes: Routes = [
{
path: 'profile',
loadChildren: () => import('./pages/public/freelancer-profile/freelancer-profile.module').then(m => m.FreelancerProfileModule)
},
{
canActivate: [LoginGuardService],
path: 'panel',
loadChildren: () => import('./pages/private/private.module').then(m => m.PrivateModule)
},
{
path: '',
loadChildren: () => import('./pages/public/public.module').then(m => m.PublicModule)
},
{
path: '',
loadChildren: () => import('./pages/landing/landing.module').then(m => m.LandingModule)
},
{
path: '',
loadChildren: () => import('./pages/public/logging/logging.module').then(m => m.LoggingModule)
},
{
path: '**',
redirectTo: '404',
}
];
i expected landing.module to be loaded only if page path is in its module but here is what happens : if page path is on logging.module , public.module and landing.module chunks are being downloaded as well. how can i fix this ? i was thinking if there was a way to check URLs and download module only if URL matches one of the paths in the module
note: i cant change urls and add prefix to avoid this because pages are indexed through search engines.