vue-router

Master Vue Router - Navigation, Guards, Lazy Loading, Meta Fields, History Modes

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "vue-router" with this command: npx skills add pluginagentmarketplace/custom-plugin-vue/pluginagentmarketplace-custom-plugin-vue-vue-router

Vue Router Skill

Production-grade skill for mastering Vue Router and building robust navigation systems.

Purpose

Single Responsibility: Teach Vue Router configuration, navigation patterns, route guards, lazy loading, and advanced routing techniques.

Parameter Schema

interface VueRouterParams {
  topic: 'config' | 'guards' | 'lazy-loading' | 'meta' | 'navigation' | 'all';
  level: 'beginner' | 'intermediate' | 'advanced';
  context?: {
    auth_required?: boolean;
    app_type?: 'spa' | 'ssr';
  };
}

Learning Modules

Module 1: Router Setup & Configuration

Prerequisites: vue-fundamentals
Duration: 2 hours
Outcome: Configure Vue Router
TopicConceptExercise
InstallationVue Router setupBasic config
Routes arrayRoute definitionsMulti-page app
History modesHash vs HTML5Production setup
Router-viewOutlet componentLayout system
Router-linkNavigation linksNavigation menu

Module 2: Dynamic & Nested Routes

Prerequisites: Module 1
Duration: 2-3 hours
Outcome: Build complex route structures
PatternExampleExercise
Dynamic params/user/:idUser profile
Optional params/user/:id?Optional filters
Catch-all/:pathMatch(.*)*404 page
Nested routes/dashboard/settingsAdmin layout
Named viewsMultiple outletsDashboard widgets

Module 3: Navigation Guards

Prerequisites: Modules 1-2
Duration: 3-4 hours
Outcome: Secure routes with guards
Guard TypeScopeUse Case
beforeEachGlobalAuth check
beforeEnterPer-routeRole check
beforeRouteEnterComponentData prefetch
beforeRouteUpdateComponentParam change
beforeRouteLeaveComponentUnsaved changes
afterEachGlobalAnalytics

Guard Composition:

router.beforeEach(async (to, from) => {
  // Auth check
  if (to.meta.requiresAuth && !isAuthenticated()) {
    return { name: 'Login', query: { redirect: to.fullPath } }
  }

  // Role check
  if (to.meta.roles && !hasRole(to.meta.roles)) {
    return { name: 'Unauthorized' }
  }

  return true
})

Module 4: Lazy Loading & Code Splitting

Prerequisites: Module 3
Duration: 2 hours
Outcome: Optimize route loading
TechniqueImplementationBenefit
Basic lazy() => import()Smaller bundles
Named chunkswebpackChunkNameGrouped loading
Prefetchingrouter.afterEachFaster navigation
Loading statesAsync componentsBetter UX

Module 5: Advanced Patterns

Prerequisites: Modules 1-4
Duration: 3 hours
Outcome: Expert routing techniques
PatternUse CaseExercise
Route metaPage metadataSEO, auth, layout
Scroll behaviorScroll positionSaved positions
TransitionsPage animationsEnter/leave effects
Route modulesLarge appsFeature-based routes

Validation Checkpoints

Beginner Checkpoint

  • Set up router with basic routes
  • Use router-link and router-view
  • Create dynamic route with params
  • Access route params in component

Intermediate Checkpoint

  • Implement auth guard
  • Create nested route layout
  • Add lazy loading to routes
  • Use route meta for titles

Advanced Checkpoint

  • Build full auth flow with guards
  • Implement route-based code splitting
  • Create route transition animations
  • Design modular route structure

Retry Logic

const skillConfig = {
  maxAttempts: 3,
  backoffMs: [1000, 2000, 4000],
  onFailure: 'provide_simpler_route'
}

Observability

tracking:
  - event: route_configured
    data: [route_count, guards_count]
  - event: navigation_pattern_learned
    data: [pattern_name, complexity]
  - event: skill_completed
    data: [routes_built, auth_implemented]

Troubleshooting

Common Issues

IssueCauseSolution
Route not matchingWrong path orderSpecific before generic
Guard infinite loopGuard → same routeCheck target route
Lazy load failsWrong import pathVerify file exists
Params undefinedMissing props: trueEnable props

Debug Steps

  1. Check Vue Devtools router tab
  2. Verify route order (specific first)
  3. Console.log in guards
  4. Check router.getRoutes()

Unit Test Template

import { describe, it, expect, beforeEach } from 'vitest'
import { createRouter, createWebHistory } from 'vue-router'
import { routes } from './routes'

describe('Router', () => {
  let router: Router

  beforeEach(() => {
    router = createRouter({
      history: createWebHistory(),
      routes
    })
  })

  it('redirects to login when not authenticated', async () => {
    await router.push('/dashboard')
    expect(router.currentRoute.value.name).toBe('Login')
  })

  it('allows access to public routes', async () => {
    await router.push('/about')
    expect(router.currentRoute.value.name).toBe('About')
  })
})

Usage

Skill("vue-router")

Related Skills

  • vue-fundamentals - Prerequisite
  • vue-pinia - Auth state for guards
  • vue-nuxt - File-based routing alternative

Resources

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

vue-pinia

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

vue-nuxt

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

vue-composition-api

No summary provided by upstream source.

Repository SourceNeeds Review