Performance: RouterView for rendering
MEDIUM IMPACT
RouterView affects page load speed and rendering by controlling which components are mounted and displayed based on the route, impacting initial render and updates.
const routes = [ { path: '/', component: () => import('./Home.vue') }, { path: '/about', component: () => import('./About.vue') } ]; // Use <router-view v-slot="{ Component }"> // <keep-alive> // <component :is="Component" /> // </keep-alive> // </router-view>
const routes = [ { path: '/', component: () => import('./Home.vue') }, { path: '/about', component: () => import('./About.vue') } ]; // In App.vue template <router-view /> // No caching
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| RouterView without caching | High (remounts the route component on navigation) | Multiple reflows per navigation | High paint cost due to full remount | [X] Bad |
| RouterView with lazy loading and keep-alive | Low (mounts only needed components, caches them) | Single reflow on first load | Low paint cost on navigation | [OK] Good |