vue-router-best-practices

Document Vue Router 4 guard patterns and param change handling for Vue 3 apps.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/ajiu9/skills --skill vue-router-best-practices-ajiu9
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vue-router-best-practices
Source: https://github.com/ajiu9/skills/tree/main/skills/vue-router-best-practices
Command: npx skills add https://github.com/ajiu9/skills --skill vue-router-best-practices-ajiu9

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Vue Router has many subtle gotchas around navigation guards, route params, and lifecycle hooks. This guide consolidates patterns and best practices to avoid common pitfalls.

Core Features & Use Cases

  • Per-route guards vs in-component guards and when to use each.
  • Handling param changes with onBeforeRouteUpdate and watch.
  • Best practices for async navigation guards and preventing infinite redirects.

Quick Start

Follow the patterns in this guide to implement robust Vue Router guards in your app.

Frequently Asked Questions about vue-router-best-practices

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

FAQPage Schema
What is the difference between per-route guards and in-component guards in Vue Router?

Per-route guards apply to specific routes globally, while in-component guards like beforeRouteEnter execute within the component itself; choosing between them depends on whether navigation logic should be centralized or tightly coupled to component lifecycle.

How do I handle param changes in Vue 3 without triggering a full component remount?

Handle param changes using onBeforeRouteUpdate or watchers to react to dynamic route updates; this prevents full component remounts by catching navigation updates within the existing component lifecycle.

What's the best way to prevent infinite redirects in Vue Router navigation guards?

Prevent infinite redirects in Vue Router navigation guards by adding explicit conditional checks before calling next with a redirect path; this avoids loops when a guard re-triggers the same route.

How do async navigation guards work in Vue Router 4?

Vue Router 4 async navigation guards work by resolving promises before completing navigation; failing to resolve or reject properly leaves the navigation hanging indefinitely.

Does this Vue Router guide cover lifecycle edge cases for Vue 3 apps?

Yes, this Vue Router guide covers Vue 3 lifecycle edge cases, specifically addressing how in-component guards interact with param changes and navigation pitfalls in Vue Router 4.