vue-router-best-practices
antfu/skills
提供 Vue Router 4 的最佳實踐,包括導航守衛、路由引數以及路由元件的生命週期互動。
...展開全部Vue Router 最佳實踐、常見陷阱及導航模式。
導航守衛
- 在不同引數間導航至同一路由 → 參見 router-beforeenter-no-param-trigger
- 在 beforeRouteEnter 守衛中訪問元件例項 → 參見 router-beforerouteenter-no-this
- 導航守衛發起 API 呼叫但未等待結果 → 參見 router-guard-async-await-pattern
- 使用者陷入無限重定向迴圈 → 參見 router-navigation-guard-infinite-loop
- 導航守衛使用了已廢棄的 next() 函式 → 參見 router-navigation-guard-next-deprecated
路由生命週期
- 在同一路由間導航時資料過時 → 參見 router-param-change-no-lifecycle
- 元件解除安裝後事件監聽器仍然存在 → 參見 router-simple-routing-cleanup
設定
- 構建生產環境單頁應用 → 參見 router-use-vue-router-for-production
---
name: vue-router-best-practices
description: Provides best practices for Vue Router 4, including navigation guards, route params, and route-component lifecycle interactions.
license: MIT
---
Vue Router best practices, common gotchas, and navigation patterns.
### Navigation Guards
- Navigating between same route with different params → See [router-beforeenter-no-param-trigger](reference/router-beforeenter-no-param-trigger.md)
- Accessing component instance in beforeRouteEnter guard → See [router-beforerouteenter-no-this](reference/router-beforerouteenter-no-this.md)
- Navigation guard making API calls without awaiting → See [router-guard-async-await-pattern](reference/router-guard-async-await-pattern.md)
- Users trapped in infinite redirect loops → See [router-navigation-guard-infinite-loop](reference/router-navigation-guard-infinite-loop.md)
- Navigation guard using deprecated next() function → See [router-navigation-guard-next-deprecated](reference/router-navigation-guard-next-deprecated.md)
### Route Lifecycle
- Stale data when navigating between same route → See [router-param-change-no-lifecycle](reference/router-param-change-no-lifecycle.md)
- Event listeners persisting after component unmounts → See [router-simple-routing-cleanup](reference/router-simple-routing-cleanup.md)
### Setup
- Building production single-page application → See [router-use-vue-router-for-production](reference/router-use-vue-router-for-production.md)
所有檔案
0 個檔案安裝 vue-router-best-practices
將技能檔案下載並解壓至 .claude/skills/ 目錄。
下載 ZIP複製儲存庫並將技能檔案複製到您的專案中。
git clone https://github.com/antfu/skills/tree/main/skills/vue-router-best-practices # Copy SKILL.md to your .claude/skills/ directory
複製





首頁
