vue-router-v4
npx skills add https://github.com/teachingai/full-stack-skills --skill vue-router-v4
Agent 安装分布
Skill 文档
When to use this skill
Use this skill whenever the user wants to:
- Set up routing in a Vue 3 application
- Configure routes, nested routes, and named routes
- Implement navigation guards (global, per-route, in-component)
- Use programmatic navigation with
router.push(),router.replace(), etc. - Handle dynamic route matching and route parameters
- Work with route meta fields and route records
- Implement lazy loading and code splitting for routes
- Use Vue Router with Composition API (
useRouter,useRoute) - Configure different history modes (hash, HTML5 history, memory)
- Handle scroll behavior and transitions
- Implement typed routes with TypeScript
- Migrate from Vue Router 3 to Vue Router 4
- Extend RouterLink component
- Handle navigation failures and errors
- Work with dynamic routing (adding/removing routes at runtime)
How to use this skill
This skill is organized to match the Vue Router official documentation structure (https://router.vuejs.org/guide/, https://router.vuejs.org/api/). When working with Vue Router:
-
Identify the topic from the user’s request:
- Getting started/å¿«éå¼å§ â
examples/essentials/getting-started.md - Dynamic route matching/å¨æè·¯ç±å¹é
â
examples/essentials/dynamic-route-matching.md - Routes matching syntax/è·¯ç±å¹é
è¯æ³ â
examples/essentials/routes-matching-syntax.md - Named routes/å½åè·¯ç± â
examples/essentials/named-routes.md - Nested routes/åµå¥è·¯ç± â
examples/essentials/nested-routes.md - Programmatic navigation/ç¼ç¨å¼å¯¼èª â
examples/essentials/programmatic-navigation.md - Named views/å½åè§å¾ â
examples/essentials/named-views.md - Redirect and alias/éå®ååå«å â
examples/essentials/redirect-alias.md - Passing props to route components/åè·¯ç±ç»ä»¶ä¼ é props â
examples/essentials/passing-props.md - Different history modes/ä¸åçå岿¨¡å¼ â
examples/essentials/different-history-modes.md - Navigation guards/导èªå®å« â
examples/advanced/navigation-guards.md - Route meta fields/è·¯ç±å
ä¿¡æ¯ â
examples/advanced/route-meta-fields.md - Data fetching/æ°æ®è·å â
examples/advanced/data-fetching.md - Composition API/ç»åå¼ API â
examples/advanced/composition-api.md - RouterView slot/RouterView ææ§½ â
examples/advanced/routerview-slot.md - Transitions/è¿æ¸¡ææ â
examples/advanced/transitions.md - Scroll behavior/æ»å¨è¡ä¸º â
examples/advanced/scroll-behavior.md - Lazy loading routes/æå è½½è·¯ç± â
examples/advanced/lazy-loading-routes.md - Typed routes/ç±»ååè·¯ç± â
examples/advanced/typed-routes.md - Extending RouterLink/æ©å± RouterLink â
examples/advanced/extending-router-link.md - Navigation failures/导èªå¤±è´¥ â
examples/advanced/navigation-failures.md - Dynamic routing/å¨æè·¯ç± â
examples/advanced/dynamic-routing.md
- Getting started/å¿«éå¼å§ â
-
Load the appropriate example file from the
examples/directory:Essentials (åºç¡) –
examples/essentials/:examples/essentials/getting-started.md– Creating a router and basic setupexamples/essentials/dynamic-route-matching.md– Dynamic route matching with paramsexamples/essentials/routes-matching-syntax.md– Route matching syntax and patternsexamples/essentials/named-routes.md– Named routes and navigationexamples/essentials/nested-routes.md– Nested routes and RouterViewexamples/essentials/programmatic-navigation.md– Programmatic navigation with router methodsexamples/essentials/named-views.md– Named views and multiple RouterViewexamples/essentials/redirect-alias.md– Redirects and aliasesexamples/essentials/passing-props.md– Passing props to route componentsexamples/essentials/different-history-modes.md– Hash, HTML5 history, and memory modes
Advanced (é«çº§) –
examples/advanced/:examples/advanced/navigation-guards.md– Global, per-route, and in-component guardsexamples/advanced/route-meta-fields.md– Route meta fields and custom dataexamples/advanced/data-fetching.md– Data fetching strategiesexamples/advanced/composition-api.md– UsinguseRouter()anduseRoute()with Composition APIexamples/advanced/routerview-slot.md– RouterView slot propsexamples/advanced/transitions.md– Route transitions and animationsexamples/advanced/scroll-behavior.md– Scroll behavior configurationexamples/advanced/lazy-loading-routes.md– Lazy loading routes and code splittingexamples/advanced/typed-routes.md– TypeScript typed routesexamples/advanced/extending-router-link.md– Extending RouterLink componentexamples/advanced/navigation-failures.md– Handling navigation failuresexamples/advanced/dynamic-routing.md– Adding and removing routes dynamically
-
Follow the specific instructions in that example file for syntax, structure, and best practices
Important Notes:
- All examples follow Vue Router 4 API
- Examples include both JavaScript and TypeScript versions where applicable
- Each example file includes key concepts, code examples, and key points
- Always check the example file for best practices and common patterns
-
Reference API documentation in the
api/directory when needed:api/router.md– Router instance API (createRouter,addRoute,removeRoute, etc.)api/route-records.md– Route record types and propertiesapi/useRouter-useRoute.md– Composition API functions (useRouter,useRoute)api/navigation-helpers.md– Navigation helper functionsapi/router-link-router-view-components.md– RouterLink and RouterView componentsapi/history-modes-api.md– History mode APIsapi/error-and-failure-types.md– Error and failure types
-
Use templates from the
templates/directory:templates/router-setup.md– Router setup templatestemplates/route-config.md– Route configuration templates
Examples and Templates
This skill includes detailed examples organized to match the Vue Router official documentation structure (https://router.vuejs.org/guide/, https://router.vuejs.org/api/). All examples are in the examples/ directory, organized by topic:
Essentials (åºç¡) – examples/essentials/
examples/essentials/getting-started.md– Creating a router, installing Vue Router, and basic setupexamples/essentials/dynamic-route-matching.md– Dynamic route matching with params and queryexamples/essentials/routes-matching-syntax.md– Route matching syntax, catch-all routes, and regexexamples/essentials/named-routes.md– Named routes and navigation with namesexamples/essentials/nested-routes.md– Nested routes and nested RouterViewexamples/essentials/programmatic-navigation.md– Programmatic navigation withrouter.push(),router.replace(),router.go()examples/essentials/named-views.md– Named views and multiple RouterView componentsexamples/essentials/redirect-alias.md– Redirects and aliases configurationexamples/essentials/passing-props.md– Passing props to route componentsexamples/essentials/different-history-modes.md– Hash mode, HTML5 history mode, and memory mode
Advanced (é«çº§) – examples/advanced/
examples/advanced/navigation-guards.md– Global guards, per-route guards, and in-component guardsexamples/advanced/route-meta-fields.md– Route meta fields and accessing meta in guardsexamples/advanced/data-fetching.md– Data fetching strategies (before navigation, after navigation)examples/advanced/composition-api.md– UsinguseRouter()anduseRoute()with Composition APIexamples/advanced/routerview-slot.md– RouterView slot props and custom renderingexamples/advanced/transitions.md– Route transitions and animationsexamples/advanced/scroll-behavior.md– Scroll behavior configurationexamples/advanced/lazy-loading-routes.md– Lazy loading routes and code splittingexamples/advanced/typed-routes.md– TypeScript typed routes and type safetyexamples/advanced/extending-router-link.md– Extending RouterLink componentexamples/advanced/navigation-failures.md– Handling navigation failures and errorsexamples/advanced/dynamic-routing.md– Adding and removing routes dynamically at runtime
Templates Directory (templates/)
templates/router-setup.md– Router setup templates for different scenariostemplates/route-config.md– Route configuration templates
To use examples:
- Identify the topic from the user’s request
- Load the appropriate example file from the corresponding directory
- Follow the instructions, syntax, and best practices in that file
- Adapt the code examples to your specific use case
To use templates:
- Reference
templates/router-setup.mdfor router setup templates - Use
templates/route-config.mdfor route configuration templates - Adapt templates to your specific needs and coding style
API Reference
Detailed API documentation is available in the api/ directory, organized to match the official Vue Router API documentation structure:
Router API (api/router.md)
createRouter()– Creating a router instance- Router instance methods:
addRoute(),removeRoute(),hasRoute(),getRoutes(),push(),replace(),go(),back(),forward() - Router instance properties:
currentRoute,options
Route Records API (api/route-records.md)
- Route record types and properties
- Route configuration options
Composition API (api/useRouter-useRoute.md)
useRouter()– Access router instance in setupuseRoute()– Access current route in setup
Navigation Helpers (api/navigation-helpers.md)
- Navigation helper functions and utilities
Components API (api/router-link-router-view-components.md)
RouterLinkcomponent props and usageRouterViewcomponent props and usage
History Modes API (api/history-modes-api.md)
createWebHistory()– HTML5 history modecreateWebHashHistory()– Hash modecreateMemoryHistory()– Memory mode
Error and Failure Types (api/error-and-failure-types.md)
- Navigation failure types
- Error handling
To use API reference:
- Identify the API you need help with
- Load the corresponding API file from the
api/directory - Find the API signature, parameters, return type, and examples
- Reference the linked example files for detailed usage patterns
- All API files include links to relevant example files in the
examples/directory
Best Practices
- Use named routes: Use named routes for better maintainability and refactoring
- Lazy load routes: Use dynamic imports for route components to enable code splitting
- Type safety: Use TypeScript with typed routes for better type safety
- Navigation guards: Use navigation guards appropriately (global, per-route, in-component)
- Route meta: Use route meta fields for custom data and permissions
- History mode: Choose the appropriate history mode based on deployment environment
- Scroll behavior: Configure scroll behavior for better UX
- Error handling: Handle navigation failures gracefully
Resources
- Official Guide: https://router.vuejs.org/guide/
- API Reference: https://router.vuejs.org/api/
- Migration Guide: https://router.vuejs.org/guide/migration/
- GitHub Repository: https://github.com/vuejs/router
Keywords
Vue Router, router, routing, navigation, route, routes, nested routes, named routes, dynamic routes, route params, route query, navigation guards, route meta, programmatic navigation, RouterLink, RouterView, useRouter, useRoute, history mode, hash mode, HTML5 history, lazy loading, code splitting, typed routes, TypeScript, è·¯ç±, 导èª, è·¯ç±å®å«, åµå¥è·¯ç±, å½åè·¯ç±, å¨æè·¯ç±, ç¼ç¨å¼å¯¼èª, æå è½½, ç±»ååè·¯ç±