How to define child routes of lazy loaded standalone component? In app.routes.ts
I defined:
export const routes: Routes = [
{
path: 'some/parent',
loadComponent: () => import('./my-parent/my-parentponent').then((m) => m.ParentComponent),
children: [
{ path: '', redirectTo: 'child1', pathMatch: 'full' },
{ path: 'child1', loadComponent: () => import('./my-parent/child-one/child-oneponent').then(m => m.ChildOneComponent) },
{ path: 'child2', loadComponent: () => import('./my-parent/child-two/child-twoponent').then(m => m.ChildTwoComponent) },
]
},...
The parent component template contains a router-outlet
:
<head></head>
<router-outlet></router-outlet>
<foot></foot>
Does this approach align with Angular's standalone architecture? Is it possible, or does it make sense, for only the parent component to be lazy-loaded while the child components are not?
I'm using an Angular 19 SSR standalone app.
How to define child routes of lazy loaded standalone component? In app.routes.ts
I defined:
export const routes: Routes = [
{
path: 'some/parent',
loadComponent: () => import('./my-parent/my-parent.component').then((m) => m.ParentComponent),
children: [
{ path: '', redirectTo: 'child1', pathMatch: 'full' },
{ path: 'child1', loadComponent: () => import('./my-parent/child-one/child-one.component').then(m => m.ChildOneComponent) },
{ path: 'child2', loadComponent: () => import('./my-parent/child-two/child-two.component').then(m => m.ChildTwoComponent) },
]
},...
The parent component template contains a router-outlet
:
<head></head>
<router-outlet></router-outlet>
<foot></foot>
Does this approach align with Angular's standalone architecture? Is it possible, or does it make sense, for only the parent component to be lazy-loaded while the child components are not?
I'm using an Angular 19 SSR standalone app.
it feels like subroutes of the ParentComponent should be that "module's" responsibility, and not bloat the root routing configuration
to achieve that simply use loadChildren
// main routes
export const routes: Routes = [
{
path: 'some/parent',
loadChildren: () => import('./my-parent/my-parent.component'),
},...
// parent.component
export class ParentComponent {...}
const routes: Route[] = [
{
path: '',
component: ParentComponent,
children: [
{ path: '', redirectTo: 'child1', pathMatch: 'full' },
{ path: 'child1', loadComponent: () => import('./child1/child1.component') /* don't need then piece, if component is "export default" */ },
{ path: 'child2', component: ChildTwoComponent },
]
}
]
export default routes;