Vue.js Assignment– 3
Vue Router
Basic Questions
- Create a router with dynamic route /users/:id and display the id on the page.
- Add a nested route /users/:id/profile under /users/:id and render both parent and child views.
- Pass route params as component props for /users/:id and read them in the component.
- Add a redirect from /u/:id to /users/:id and verify navigation.
- Create a catch-all 404 route that renders a NotFound component.
- Add a query string handler to /search and render q from ?q=term.
- Implement a global beforeEach guard that logs every navigation.
- Add a per-route guard on /admin that blocks navigation without a flag.
- Implement per-component guards (beforeRouteEnter/Update/Leave) on a details page.
- Add meta: { requiresAuth: true } to /dashboard and check it in a global guard.
- Add meta: { roles: [‘admin’] } to /admin and verify role check in a guard.
- Lazy-load the /reports route using dynamic import.
- Group multiple lazy routes into one chunk (webpackChunkName) and verify in devtools.
- Show a loading spinner while a lazy route component is being fetched.
- Implement scrollBehavior that restores savedPosition on back/forward.
- Customize scrollBehavior to scroll to top on route change by default.
- Support hash anchor scrolling: navigate to /docs#install and scroll to the element.
- Use router.push and router.replace and demonstrate the difference.
- Cancel navigation in a guard using next(false) (or returning false) and confirm stay.
- Add a link active class style and verify it updates on route changes.
Intermediate Questions
- Create nested routes for /projects/:id with children overview, issues, settings.
- Add a route with optional param /blog/:slug? and handle both cases.
- Use route props with a mapping function to convert page query to a number.
- Implement a global beforeResolve guard to start a page loader before data fetch.
- Implement a global afterEach hook to stop the loader and log route duration.
- Add a per-route guard that fetches user data; redirect to /login on 401.
- Add per-component beforeRouteUpdate to refetch data when :id changes.
- Create a role-based access system using meta.roles and a store; redirect unauthorized users.
- Add a route that lazy-loads and prefetches (use /* webpackPrefetch: true */) and verify network.
- Handle lazy-load failure: show a fallback component if dynamic import rejects.
- Programmatically add a route at runtime with router.addRoute and navigate to it.
- Remove a previously added route with router.removeRoute and verify 404.
- Use navigation guards to prevent leaving a dirty form (confirm dialog).
- Implement a login guard that refreshes token before allowing entry to protected routes.
- Persist last visited protected route and redirect there after successful login.
- Customize scrollBehavior to keep scroll for list → detail → back transitions only.
- Implement smooth scrolling to hash anchors using behavior: ‘smooth’.
- Create a param regex route /tickets/:id(\\d+) and block non-numeric IDs.
- Build a breadcrumb component using the matched route records.
- Add route-level code splitting for each /projects/:id/* child route and verify chunks.
Advanced Questions
- Build an auth-protected area using meta.requiresAuth, role checks, and silent token refresh in guards.
- Implement a loading skeleton + timeout fallback for slow lazy routes (cancel on user navigate away).
- Create a data-preload guard that fetches page data in beforeResolve and hydrates via props.
- Implement optimistic navigation: start rendering shell, fetch data, then replace content when ready.
- Add advanced scrollBehavior that restores per-tab scroll positions across multiple named views.
- Create a guarded wizard flow (/setup/step-1…step-3) that blocks skipping steps via direct URL.
- Implement route transitions with suspense: show a placeholder while both component and data load.
- Build a permissions matrix using meta fields (scopes) and enforce them in a single global guard.
- Add runtime feature flags to enable/disable routes without redeploy (use addRoute/removeRoute).
- Final Hands-on Project:
- App with dynamic + nested routes, 404, and redirects
- Global, per-route, and per-component guards for auth, roles, and unsaved changes
- Route meta for authorization; token refresh flow in guards
- Route-level lazy loading with error + loading states and chunk grouping
- Custom scrollBehavior for savedPosition, hash anchors, and smooth restore
- Breadcrumbs from matched records and verified code-split chunks