Lazy Loading & Transitions — Series 3
Preview — 3 of 10 questions
Given a navigation from /settings to /admin/users (a completely different, nested route), in what order do these run: the outgoing components `beforeRouteLeave`, the global `router.beforeEach`, the new routes beforeEnter, the entering component's beforeRouteEnter, and the global router.beforeResolve?
Given a route /users/:id reused across navigations (/users/1 → /users/2), beforeRouteUpdate is the recommended way to react without remounting. When might <router-view :key="route.params.id" /> (forcing a full remount instead) genuinely be the better choice despite the extra cost?
<router-view v-slot="{ Component, route }">
<component :is="Component" :key="route.params.id" />
</router-view>What does createAuthGuard let call sites do that a single hardcoded guard function couldn't?
function createAuthGuard(requiredRole) {
return (to, from) => {
if (!authStore.isLoggedIn) {
return { path: '/login', query: { redirect: to.fullPath } }
}
if (requiredRole && !authStore.hasRole(requiredRole)) {
return { path: '/forbidden' }
}
}
}
const routes = [
{ path: '/admin', component: AdminPanel, beforeEnter: createAuthGuard('admin') },
{ path: '/billing', component: Billing, beforeEnter: createAuthGuard('billing-manager') },
{ path: '/dashboard', component: Dashboard, beforeEnter: createAuthGuard() },
]Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.