vue-router-best-practices

Codify Vue Router guard patterns and lifecycle best practices for Vue 3 SPAs.

5.7k|318|Updated Jan 28, 2026
One-click install
npx skills add https://github.com/antfu/skills --skill vue-router-best-practices-antfu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vue-router-best-practices
Source: https://github.com/antfu/skills/tree/main/skills/vue-router-best-practices
Command: npx skills add https://github.com/antfu/skills --skill vue-router-best-practices-antfu

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Vue Router 4 can be tricky: misusing guards, mishandling route params, and lifecycle pitfalls lead to flaky navigation and stale data in SPAs.

Core Features & Use Cases

  • Guard patterns: Per-route and global guards, with clear guidance on when each fires.
  • Param & lifecycle handling: Strategies for reacting to param changes without stale data.
  • Common gotchas: Guidance to avoid infinite redirects, access to component instance, and async guard pitfalls.
  • Use Case: Build a robust admin dashboard with nested routes and protected sections using guard patterns and route meta.

Quick Start

Install and configure Vue Router in your project, review the reference guard patterns, and progressively apply best practices to your routes.

Frequently Asked Questions about vue-router-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent stale data when route params change in Vue Router 4?

To prevent stale data during param changes in Vue Router 4, use lifecycle-aware data loading strategies. This ensures your Vue 3 SPA properly reacts to parameter updates and fetches fresh data without relying on outdated component states.

What is the best way to structure navigation guards in a Vue 3 SPA?

The best way to structure navigation guards is codifying per-route and global guard patterns. This approach provides clear guidance on when each guard fires, ensuring robust navigation reliability and consistent route protection across complex routes.

Why does my Vue Router setup cause infinite redirects in protected routes?

Infinite redirects in Vue Router often occur from misusing navigation guards. Following established guard patterns and route meta guidelines helps avoid these common gotchas, ensuring your protected sections resolve correctly without looping.

Do I need prior Vue Router experience to use these routing patterns?

Yes, you need familiarity with Vue Router concepts. These routing patterns and best practices are designed for developers already building Vue 3 SPAs, providing guidelines and reference materials to integrate into existing standard tooling and codebases.

How do I build a robust admin dashboard with nested routes using Vue Router?

Build a robust admin dashboard by applying guard patterns and route meta to nested routes. This technique secures protected sections and ensures consistent param handling and lifecycle-aware data loading across complex administrative views.