front/.cursor/rules/spa-dev-route-fallback.mdc
zzh 5010213539
All checks were successful
Build and Deploy Front / deploy (push) Successful in 4m3s
feat: 单号截取扫描加速、登录验证码与 SPA 刷新回退
新增单号规则截取模式与本地扫描引擎;登录图形验证码;吉祥物空态;开发态从 Router 自动回退 PC/H5 刷新直链。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-14 19:33:27 +08:00

28 lines
1.4 KiB
Plaintext
Raw Permalink 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.

---
description: 新增前端页面时必须挂 Vue Router;开发态刷新回退从路由自动收集,禁止再手维护 vite 白名单
globs: src/router/**/*.ts, src/views/**/*.vue, vite.config.ts, config/devSpaRoutes.ts
alwaysApply: true
---
# 开发态 SPA 刷新 / 直链回退
## 强制约定
新增或迁移中后台 / H5 页面时:
1. **必须**把路由写进 `src/router/routes/newModules/*.ts` 或 `src/router/index.ts`(path 用 camelCase,与现网一致)。
2. **不要**再往 `vite.config.ts` 里追加 `/channel/xxx` 之类手工 SPA 白名单。
3. 开发服务器用 `config/devSpaRoutes.ts` **从 Router 自动收集**页面路径;改完 router 后若 Vite 未重载,重启一次 `pnpm dev`。
## 原理(避免再踩坑)
- 页面与 API 常共用前缀(如 `/channel`、`/system`)。
- 刷新直链若未回退 `index.html`,会被 proxy 打到后端 → **整页空白 404**。
- 自动收集用**精确匹配**页面 path,因此 `/system/approval/definition` 是页,`/system/approval/definition/list` 仍走 API。
- **H5 特例**:`/h5` 与 `/h5/**` 一律按 SPA 回退(无同前缀 API);客户中心与管理端 H5(含 `ops/*`、订单详情深链)刷新与 PC 同一套机制。
## Agent 自检
加页面后自问:路由文件是否已包含该 path?未写路由 = 刷新仍会挂。
加 H5 页:path 挂在 `/h5` 或 `/h5/admin` 下即可,不必改 `vite.config.ts`。