skills/dev-skills/angular-developer/references/loading-strategies.md
Angular supports two main strategies for loading routes and components to balance initial load time and navigation responsiveness.
Components are bundled into the initial JavaScript payload and are available immediately.
{ path: 'home', component: Home }
Components or routes are loaded only when the user navigates to them. This creates separate JavaScript "chunks".
Use loadComponent to fetch the component on demand.
{
path: 'admin',
loadComponent: () => import('./admin/admin.component').then(m => m.AdminComponent)`,
}
Use loadChildren to fetch a set of routes.
{
path: 'settings',
loadChildren: () => import('./settings/settings.routes'),
}
Loader functions run within the injection context of the current route. This allows you to call inject() to make context-aware loading decisions.
{
path: 'dashboard',
loadComponent: () => {
const flags = inject(FeatureFlags);
return flags.isPremium
? import('./premium-dashboard')
: import('./basic-dashboard');
},
}