Performance: Vue Router installation and setup
MEDIUM IMPACT
This affects the initial page load speed and navigation responsiveness by adding routing logic and components to the Vue app.
import { createApp } from 'vue'; import { createRouter, createWebHistory } from 'vue-router'; import App from './App.vue'; import Home from './components/Home.vue'; import About from './components/About.vue'; const routes = [ { path: '/', component: Home }, { path: '/about', component: About } ]; const router = createRouter({ history: createWebHistory(), routes }); const app = createApp(App); app.use(router); app.mount('#app');
import { createApp } from 'vue'; import App from './App.vue'; const app = createApp(App); app.mount('#app');
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No Router (full reloads) | High (full page reload) | Many (full page layout) | High (full repaint) | [X] Bad |
| Vue Router with eager loading | Moderate (component swaps) | Few (component layout changes) | Moderate (partial repaint) | [!] OK |
| Vue Router with lazy loading | Low (only loaded components) | Few (minimal layout) | Low (minimal repaint) | [OK] Good |