指导在前端项目中按团队规范创建和维护路由,包括目录结构、Page 与 Loader 职责划分及懒加载用法。当前端需要新增或重构页面路由时使用本技能。
在开始创建之前,请务必阅读以下关键规范:
必读规范:
.agents/rules/03-项目结构.md - 目录结构要求(特别是 index.module.scss).agents/rules/06-路由规范.md - 路由配置约束常见错误警告:
.module.scss 后缀,禁止使用 .scsskebab-case,例如 login、ai-editor每个路由对应 src/routes/<route-name>/ 目录:
src/routes/login/
├─ Page.tsx # 页面主组件
├─ Loader.tsx # 懒加载包装
└─ index.module.scss # 样式文件(必须是 .module.scss)
关键要求:
index.module.scss(非 .scss)Page 组件kebab-case// src/routes/login/Page.tsx
import React from 'react';
import styles from './index.module.scss'; // 必须是 .module.scss
const LoginPage: React.FC = () => {
return <div className={styles.loginPage}>LoginPage</div>;
};
export default LoginPage;
验证点:
Page.tsx./index.module.scss// src/routes/login/Loader.tsx
import React from 'react';
import {ErrorBoundary, RouterLoading} from '@/components';
const Component = React.lazy(
() => import(/* webpackChunkName: "login" */ './Page')
);
const Loader: React.FC = () => {
return (
<ErrorBoundary>
<React.Suspense fallback={<RouterLoading />}>
<Component />
</React.Suspense>
</ErrorBoundary>
);
};
export default Loader;
验证点:
Loader.tsxReact.lazy 懒加载 Page在 src/routes/index.tsx 中注册:
import LoginLoader from './login/Loader';
const routes = [
{
path: '/login',
element: <LoginLoader />,
isAuthenticated: true, // 根据实际需求设置
},
// ...
];
验证点:
./login/Loader创建完成后,检查目录结构是否符合规范:
src/routes/<route-name>/
├─ Page.tsx ✓
├─ Loader.tsx ✓
└─ index.module.scss ✓(必须是 .module.scss)
快速验证命令:
ls -la src/routes/<route-name>/
应该看到三个文件,且样式文件后缀为 .module.scss。
如果页面需要专用组件,创建 components/ 目录:
src/routes/ai-editor/
├─ Page.tsx
├─ Loader.tsx
├─ index.module.scss
└─ components/ # 页面专用组件
└─ xxx/
├─ index.tsx
└─ index.module.scss
组件放置规则(详见 .agents/rules/04-组件规范.md):
src/routes/<route>/components/src/components/创建完成后,逐项核对:
kebab-casePage.tsxLoader.tsxindex.module.scss(非 .scss)./index.module.scss样式还原检查:涉及 UI 还原的样式开发,请参考 .agents/skills/create-proposal/SKILL.md 中的「样式还原验证检查清单」及对应页面的 docs/样式还原/<名称>-UI分析清单.md。
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer