vue-router-best-practices

Implement Vue 3 Router 4 guards and navigation lifecycle patterns correctly.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Vue Router best practices, common gotchas, and navigation patterns are compiled to help developers implement robust routing behavior in Vue 3 SPAs.

Core Features & Use Cases

  • Per-route guards, global guards patterns, and lifecycle interactions guidance.
  • Handling param and query changes with in-component guards and lifecycle hooks.
  • Practical scenarios like avoiding infinite redirects and ensuring data loading in guards.

Quick Start

Try a guided example by implementing a per-route guard on a sample route and verify navigation behavior.

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 handle Vue Router param changes with in-component guards?

Handle Vue Router param changes by combining the beforeRouteUpdate in-component guard with navigation lifecycle hooks to manage data fetching and component state updates without full remounting.

What is the best way to structure per-route guards in Vue 3 SPAs?

The best way to structure per-route guards in Vue 3 SPAs is using the beforeEnter guard for route-specific access control, keeping global guards for application-wide concerns and avoiding infinite redirect loops.

How do navigation lifecycle interactions work with Vue Router guards?

Vue Router navigation lifecycle interactions work by executing global, per-route, and in-component guards in a specific sequence, allowing you to intercept, validate, or cancel navigation before component rendering.

How do I implement robust async Vue Router guards with error handling?

Implement robust async Vue Router guards by returning Promises from your guard functions, using proper return values for redirects, and wrapping asynchronous operations with try-catch blocks for error handling.

Why does my Vue Router guard cause an infinite redirect loop?

Vue Router guards cause infinite redirect loops when a guard condition repeatedly redirects to a route that triggers the same guard, which you fix by adding precise path checks before redirecting.

Does Vue Router 4 beforeRouteUpdate work for query changes in Vue 3?

Vue Router 4 beforeRouteUpdate works for query changes in Vue 3 when navigating to the same component, triggering the guard so you can fetch new data without destroying and recreating the component instance.