Performance: Nested routes and child views
MEDIUM IMPACT
Nested routes affect the rendering speed of views and the complexity of DOM updates when switching between child components.
const routes = [ { path: '/parent', component: ParentView, children: [ { path: 'child', component: () => import('./ChildView.vue') // lazy load child } ] } ]; // In ParentView.vue template <template> <div> <router-view /> <!-- renders matched child route --> </div> </template>
const routes = [ { path: '/parent', component: ParentView, children: [ { path: 'child', component: ChildView } ] } ]; // In ParentView.vue template <template> <div> <ChildView /> <!-- directly imported child component --> </div> </template>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct child component import inside parent | High (all children mounted upfront) | Multiple reflows on initial load | High paint cost due to many nodes | [X] Bad |
| Lazy-loaded child routes with <router-view> | Low (children mounted on demand) | Single reflow per route change | Lower paint cost with fewer nodes | [OK] Good |