Files
tangguo_admin/.cursor/skills/vue2-route-permission/SKILL.md
T
rootandClaude Opus 5 d999a5c0e6 Initial commit
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 12:02:35 +08:00

57 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
name: vue2-route-permission
description: Use when adding or modifying route/menu/permission access in this Vue2 admin project, including module router files, permissionRouter aggregation, sidebar visibility, and route metadata consistency.
disable-model-invocation: true
---
# Vue2 Route Permission
## 适用场景
- 新增一个业务页面,需要接入菜单与路由
- 新增一个模块路由文件并接入 `permissionRouter`
- 调整页面可见性、菜单结构、入口名称
- 排查“路由已写但菜单不显示 / 可见但不可访问”问题
## 本项目路由结构认知
- 模块路由拆分在 `src/router/*.js`(例如 `signin.js`)
- 聚合路由在 `src/router/permissionRouter.js`
- 侧边栏使用 `store.state.routerList` 渲染(见 `src/views/main/components/nav.vue`)
## 接入原则
- **单模块独立**:每个业务域维护自己的路由文件
- **统一聚合出口**:模块路由必须在 `permissionRouter.js` 引入并加入数组
- **元信息一致**:`title`、`meta.title`、`name`、`path` 保持语义一致
- **层级清晰**:一级菜单挂在 `Main` 下,子页面在 `children`
## 新页面接入流程
1. 在 `src/views` 创建页面组件并命名清晰
2. 在对应模块路由文件新增子路由(或新建模块路由文件)
3. 设置基础字段:`path`、`name`、`title`、`meta.title`
4. 需要缓存时补 `meta.keepAlive`
5. 在 `permissionRouter.js` 引入并追加模块路由
6. 验证菜单显示、点击跳转、激活状态、刷新后可访问
## 字段约定
- `path`:使用短横线风格,避免含糊缩写
- `name`:驼峰命名,保持唯一
- `title`:用于菜单与页面文案,避免同义不同字
- `icon`:仅一级菜单使用,沿用 Element 图标
- `meta.title`:与 `title` 保持一致,方便统一读取
## 常见问题处理
- **菜单不显示**:检查模块路由是否已加入 `permissionRouter` 聚合数组
- **菜单显示但跳转异常**:检查 `path` 与组件导入是否正确
- **激活态不正确**:检查路由跳转后 `activeRouter` 是否对应当前 `path`
- **刷新丢失访问**:检查路由注册时机和权限数据初始化顺序
## 快速参考
- 接入示例:见 [examples.md](examples.md)
- 自检清单:见 [checklist.md](checklist.md)