Performance: Why routing is needed for SPAs
Routing in SPAs affects page load speed and interaction responsiveness by managing content changes without full page reloads.
this.$router.push('/about');
window.location.href = '/about';
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full page reload on navigation | High (reloads entire DOM) | Multiple (full reflow) | High (full repaint) | [X] Bad |
| Client-side routing with Vue Router | Low (updates small DOM parts) | Single or none | Low (partial repaint) | [OK] Good |
Routing in SPAs helps to:path and component keys.path and component.const routes = [
{ path: '/', component: Home },
{ path: '/about', component: About }
];
// User visits '/about'const routes = [
{ path: '/home', component: Home },
{ path: '/about', component: About }
]
const router = createRouter({
history: createWebHistory,
routes
})createWebHistory without parentheses, so history is not set correctly.Pass the test and this pattern moves unknown