vue-router-best-practices

Resolve Vue Router 4 navigation guard and route lifecycle issues.

8|1|Updated Feb 28, 2026
One-click install
npx skills add https://github.com/belos-street/skill-kit --skill vue-router-best-practices-belos-street
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vue-router-best-practices
Source: https://github.com/belos-street/skill-kit/tree/main/skills/vue-router-best-practices
Command: npx skills add https://github.com/belos-street/skill-kit --skill vue-router-best-practices-belos-street

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Many Vue Router apps suffer from subtle navigation issues: route-level guards not firing on param/query changes, beforeRouteEnter access misconceptions, unawaited async guards, infinite redirect loops, and stale component state when the same component is reused for different params. These problems lead to security gaps, broken UX, and hard-to-debug navigation failures in production.

Core Features & Use Cases

  • Guard semantics & ordering: Clear explanations of when global, per-route, and in-component guards run and which patterns to use for entry vs update scenarios.
  • Async and return-based patterns: Recommendations to await promises, return route objects to redirect, and replace deprecated next() usage to avoid hangs and double-calls.
  • Lifecycle and param handling: Strategies for onBeforeRouteUpdate, watching route params, or using keys to force re-creation to prevent stale data.
  • Debugging redirect loops & cleanup: Practical checks to avoid infinite redirects, add escape hatches, and ensure event listeners and handlers are cleaned up.
  • Use Case: Securely enforce access checks for /orders/:id across both initial entry and intra-route param changes without causing redirects or stale UI.

Quick Start

Audit my router configuration for guard ordering, async handling, param-change updates, and potential redirect loops and provide prioritized fixes.

Frequently Asked Questions about vue-router-best-practices

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

FAQPage Schema
Why do my Vue Router navigation guards not fire when only the route params change?

Vue Router navigation guards often fail to fire on param changes because the same component is reused. You should use onBeforeRouteUpdate or watch route params to detect updates and prevent stale component state during client-side navigation.

How do I handle async navigation guards in Vue Router without causing hangs?

To handle async navigation guards in Vue Router without hangs, you must await promises and return route objects to redirect. Replacing deprecated next() usage with proper async/return patterns prevents hangs and double-calls during client-side navigation.

What is the execution order of global, per-route, and in-component guards in Vue Router?

The execution order of Vue Router guards follows a specific sequence: global, per-route, then in-component guards. Understanding this ordering helps enforce entry vs update scenarios and apply route-level validation correctly during navigation.

How do I fix infinite redirect loops in Vue Router auth checks?

To fix infinite redirect loops in Vue Router auth checks, add escape hatches to your navigation guards and verify redirect conditions. Practical checks prevent redirect loops during async auth checks and route-level validation.

Does beforeRouteEnter have access to the component instance in Vue Router 4?

beforeRouteEnter does not have direct access to the component instance in Vue Router 4. You must use the next callback with a vm argument to access the instance, avoiding common beforeRouteEnter access misconceptions.

What is the best way to prevent stale UI when reusing a component for different route params?

The best way to prevent stale UI when reusing a component for different route params is using onBeforeRouteUpdate, watching route params, or applying keys to force re-creation. These strategies prevent stale data during param changes.