Performance: Nested routes and child views
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 |
<router-view /> is placed.children array property of the parent route object.children: [{ path: 'child', component: Child }]. Options C and D use wrong keys or types. { path: '/parent/child', component: Child } defines a separate route, not nested./dashboard/settings?
const routes = [
{ path: '/dashboard', component: Dashboard, children: [
{ path: 'settings', component: Settings }
]}
];
// Dashboard.vue template:
// Dashboard
// Settings.vue template:
// Settings Page
<router-view /> renders Settings component.<h1>Dashboard</h1> and Settings shows <h2>Settings Page</h2>. Both appear together.const routes = [
{ path: '/profile', component: Profile, children: [
{ path: 'edit', component: EditProfile }
]}
];
// Profile.vue template:
// Profile Page
<router-view />. Without it, child views won't show.<h1>Profile Page</h1> and no <router-view />, so child routes can't render./shop shows a Shop component and /shop/products shows a Products component inside Shop. Which setup correctly achieves this and ensures accessibility and responsiveness?
A) Define routes with children array, use <router-view /> in Shop, and add ARIA roles and responsive CSS.
B) Define separate routes for /shop and /shop/products without nesting, and use CSS media queries only.
C) Use nested routes but omit <router-view /> in Shop and rely on v-if to show Products.
D) Use nested routes with children but place <router-view /> outside Shop component.Pass the test and this pattern moves unknown