Performance: Defining routes
This affects the initial page load speed and navigation responsiveness by controlling how components are loaded and rendered.
const routes = [ { path: '/', component: () => import('./views/Home.vue') }, { path: '/about', component: () => import('./views/About.vue') } ];
import Home from './views/Home.vue'; import About from './views/About.vue'; const routes = [ { path: '/', component: Home }, { path: '/about', component: About } ];
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Eager route imports | Low | Low | High (due to large JS bundle) | [X] Bad |
| Lazy-loaded routes | Low | Low | Low (smaller JS bundle) | [OK] Good |
const routes = [
{ path: '/', component: HomeView },
{ path: '/about', component: AboutView }
];
const router = createRouter({
history: createWebHistory(),
routes
});
What component will show when the URL is '/about'?const routes = [
{ path: '/contact', component ContactView }
];Pass the test and this pattern moves unknown