Performance: Navigation guards (beforeEach, beforeEnter)
MEDIUM IMPACT
This affects page load speed and interaction responsiveness by controlling route changes and blocking navigation until checks complete.
router.beforeEach(async (to, from, next) => { try { const isAuthenticated = await asyncAuthCheck(); if (isAuthenticated) next(); else next('/login'); } catch { next('/login'); } });
router.beforeEach((to, from, next) => { // Synchronous heavy computation or blocking API call const isAuthenticated = heavyAuthCheck(); if (isAuthenticated) next(); else next('/login'); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous heavy guard | Minimal | 0 | Blocks paint until done | [X] Bad |
| Asynchronous guard with async/await | Minimal | 0 | Non-blocking paint | [OK] Good |