vue-router-best-practices

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

Updated Jan 29, 2026
One-click install
npx skills add https://github.com/trcat/ai-todo-list --skill vue-router-best-practices-trcat
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vue-router-best-practices
Source: https://github.com/trcat/ai-todo-list/tree/main/.agents/skills/vue-router-best-practices
Command: npx skills add https://github.com/trcat/ai-todo-list --skill vue-router-best-practices-trcat

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Vue Router can be tricky; this skill consolidates best practices to avoid common gotchas around guards, route params, and lifecycle interactions, enabling robust navigation flows.

Core Features & Use Cases

  • Guided guards usage: per-route guards, in-component guards, and global guards with correct return semantics.
  • Param-change handling: strategies for route-param updates without triggering unwanted re-renders or data staleness.
  • Lifecycle-aware routing: correct use of beforeRouteEnter, beforeRouteUpdate, beforeRouteLeave, and lifecycle hooks.
  • Infinite redirect prevention: patterns to prevent redirect loops and improper navigation decisions.

Quick Start

Review the Vue Router best-practices references and integrate guard patterns into a Vue 3 project. Refactor existing routing logic to use return-based guards, implement onBeforeRouteUpdate for param changes, and validate all navigation flows.

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 on the same route without triggering unwanted re-renders?

To handle Vue Router param changes on the same route, use the beforeRouteUpdate in-component guard or onBeforeRouteUpdate. This ensures proper lifecycle management and prevents data staleness without triggering full component re-renders.

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

Infinite redirect loops in Vue Router navigation guards often occur from improper return semantics. Implementing return-based guard patterns and validating navigation decisions within global or per-route guards prevents these redirect cycles.

What is the best way to structure Vue Router global and per-route guards in Vue 3?

The best way to structure Vue Router guards is using return-based patterns for per-route guards like beforeEnter and global guards. This codifies correct return semantics to ensure robust navigation flows in Vue 3.

When do I use beforeRouteEnter versus beforeRouteUpdate in Vue Router?

Use beforeRouteEnter when loading data before a component instance is created, and beforeRouteUpdate when reacting to route param changes on an existing component. Correct lifecycle-aware routing prevents data staleness.

Does this Vue Router best practices guidance apply to Vue 2 projects?

This guidance specifically applies to Vue 3 projects using Vue Router 4. It covers param changes, per-route guards, and global guard strategies tailored for the Vue 3 ecosystem and Vue Router 4 features.