---
name: "vue-router-4-navigation-guards"
description: "Manage client-side routing, authentication guards, scroll behavior, and nested views in Vue 3."
metadata:
  author: "Eduardo San Martin Morote"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "vue router beforeeach auth guard"
  - "scrollbehavior vue router"
  - "dynamic route params vue router"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Vue Router 4 Route Guards & Dynamic Route Matching

Configures Vue Router 4: defining RouteRecordRaw hierarchies, beforeEach global auth guards, per-route guards (beforeEnter), dynamic route matching with regex params, and smooth scrollBehavior restoration.

## When to Invoke
Invoke this skill whenever you need to:
- vue router beforeeach auth guard
- scrollbehavior vue router
- dynamic route params vue router

## Execution SOP & Rules
1. Define routes array with typed RouteRecordRaw and meta: { requiresAuth: true }.
2. Attach router.beforeEach((to, from) => { if (to.meta.requiresAuth && !isAuthenticated()) return '/login'; }).
3. Configure scrollBehavior(to, from, savedPosition) to return savedPosition || { top: 0 }.
4. Use router.push({ name: 'profile', params: { id: user.id } }) for type-safe programmatic navigation.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
