admin管理员组文章数量:1307570
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-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.
Share Improve this question asked Feb 2 at 15:07 MurmulodiMurmulodi 6891 gold badge5 silver badges23 bronze badges 1- 1 It all depends on what you want to achieve. Lazy-loading child components can be beneficial for large applications, especially if they are independent or infreq used. But if these adjectives do not describe your child component it will prob just add overhead cost for the client. Be mindful that the lazy loaded components will be visible as a downloaded package in your network tab. But if you inspect your main page, you will see only what is rendered by the server in html. If your users are going to have to go through this part of the app often, you might want to have it rendered by the server. – H3AR7B3A7 Commented Feb 2 at 16:01
1 Answer
Reset to default 4it 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-parentponent'),
},...
// parentponent
export class ParentComponent {...}
const routes: Route[] = [
{
path: '',
component: ParentComponent,
children: [
{ path: '', redirectTo: 'child1', pathMatch: 'full' },
{ path: 'child1', loadComponent: () => import('./child1/child1ponent') /* don't need then piece, if component is "export default" */ },
{ path: 'child2', component: ChildTwoComponent },
]
}
]
export default routes;
本文标签: Angular 19 routing child components in standalone architectureStack Overflow
版权声明:本文标题:Angular 19 routing child components in standalone architecture - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741843959a2400672.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论