vue-router-best-practices

Audit Vue Router 4 projects and refactor navigation guards with async handling.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Vue Router best practices help developers avoid common navigation pitfalls and lifecycle traps in Vue Router 4, ensuring reliable routing behavior in SPAs.

Core Features & Use Cases

  • Guard patterns: using beforeEnter, beforeRouteEnter, onBeforeRouteUpdate, and global guards with proper async handling.
  • Lifecycle awareness: ensuring parameter changes, lifecycle hooks, and component reuse are managed without stale data.
  • Anti-patterns and remedies: diagnosing infinite redirects and param-change issues, leveraging route meta and per-route guards for robust auth and access control.

Quick Start

Audit a Vue Router project and refactor guards to use explicit returns and async/await, add onBeforeRouteUpdate for parameter changes, and adopt meta-based protections.

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 prevent infinite redirects in Vue Router navigation guards?

To prevent infinite redirects in Vue Router navigation guards, enforce correct async handling and apply per-route guards with explicit returns. This ensures reliable routing behavior and stops redirect loops in SPA projects.

How do I handle Vue Router parameter changes without stale data?

Handling Vue Router parameter changes without stale data requires using onBeforeRouteUpdate and maintaining lifecycle awareness. This ensures component reuse and lifecycle hooks are managed correctly when route params change.

What is the best way to structure Vue Router auth and access control?

The best way to structure Vue Router auth and access control is leveraging route meta fields and per-route guards. This pattern provides robust access management by enforcing explicit returns and async/await in global guards.

Why does my Vue Router beforeEnter guard fail to resolve async operations?

Vue Router beforeEnter guards fail to resolve async operations when missing explicit async handling. Applying async/await and explicit returns within navigation guards ensures proper resolution and prevents hanging navigation.

Do I need onBeforeRouteUpdate for component reuse in Vue Router 4?

Yes, you need onBeforeRouteUpdate for component reuse in Vue Router 4. It manages parameter changes and lifecycle interactions without stale data, ensuring safe and scalable routing patterns in single-page applications.