vue-router-best-practices

Implement Vue Router 4 navigation guards in Vue 3 projects.

Updated Dec 30, 2025
One-click install
npx skills add https://github.com/NKDShinKu/NKDShinKu --skill vue-router-best-practices-nkdshinku
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vue-router-best-practices
Source: https://github.com/NKDShinKu/NKDShinKu/tree/main/.agents/skills/vue-router-best-practices
Command: npx skills add https://github.com/NKDShinKu/NKDShinKu --skill vue-router-best-practices-nkdshinku

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill provides practical guidance for architecting robust Vue Router navigation guards and route lifecycle interactions in Vue 3 applications.

Core Features & Use Cases

  • Per-route guards and navigation patterns for secured, predictable routing
  • In-component guards (onBeforeRouteUpdate) to react to param changes without remounts
  • Global guards and lifecycle orchestration to ensure consistent navigation behavior
  • Reference-driven patterns to handle common gotchas and edge cases

Quick Start

  1. Install Vue Router 4 in your project and wire up routes with explicit guards (beforeEnter, beforeEach) where appropriate.
  2. Use in-component onBeforeRouteUpdate to respond to param or query changes without re-creating the component.
  3. Read the reference guidelines in reference/ for concrete examples and edge-case resolutions.

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 without remounting the component?

To handle Vue Router param changes without remounting, use the in-component guard onBeforeRouteUpdate. This allows your Vue 3 component to react to param or query changes dynamically without re-creating its lifecycle.

What is the best way to structure Vue Router navigation guards for predictable routing?

The best way to structure Vue Router navigation guards is by combining global beforeEach hooks with per-route beforeEnter guards. This pattern ensures secured, predictable routing behavior across your Vue 3 application.

Does this Vue Router guidance apply to Vue 2 projects?

No, this Vue Router guidance does not apply to Vue 2 projects. It specifically targets Vue 3 applications using Vue Router 4, focusing on modern route guards, lifecycle interactions, and async handling patterns.

How do I manage async operations inside Vue Router navigation guards?

You manage async operations inside Vue Router navigation guards by returning Promises or utilizing async/await within your guard functions. This ensures the navigation waits for your asynchronous logic to resolve before proceeding.

Why does my Vue 3 component lifecycle not trigger when only the route param changes?

Your Vue 3 component lifecycle does not trigger because Vue Router reuses the same component instance for param changes by default. Implement onBeforeRouteUpdate to respond to these in-component updates without a full remount.

What are common gotchas when implementing Vue Router per-route guards?

Common gotchas when implementing Vue Router per-route guards include improper async handling and unexpected navigation cancellations. Using reference-driven patterns for beforeEnter guards helps resolve these edge cases predictably.