cloudwerk-routing
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCloudwerk Routing
Cloudwerk 路由
File-based routing conventions for Cloudwerk. The directory structure maps directly to URL patterns, with special filenames determining behavior.
app/Cloudwerk的基于文件的路由规范。目录结构直接映射到URL模式,特殊文件名决定路由行为。
app/When to Apply
适用场景
Reference these guidelines when:
- Creating new pages or API routes in a Cloudwerk app
- Adding layouts that wrap multiple pages
- Implementing middleware for auth, rate limiting, or request processing
- Using dynamic route segments (,
[id])[...slug] - Loading data with or handling mutations with
loader()action() - Adding error or not-found boundaries
参考本规范的场景包括:
- 在Cloudwerk应用中创建新页面或API路由时
- 添加可包裹多个页面的布局时
- 实现用于身份验证、速率限制或请求处理的中间件时
- 使用动态路由段(、
[id])时[...slug] - 使用加载数据或使用
loader()处理变更时action() - 添加错误边界或404页面边界时
Rule Categories by Priority
规则分类及优先级
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Route Files | CRITICAL | |
| 2 | Dynamic Parameters | HIGH | |
| 3 | Data Loading | HIGH | |
| 优先级 | 分类 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 路由文件 | 关键 | |
| 2 | 动态参数 | 高 | |
| 3 | 数据加载 | 高 | |
Quick Reference
快速参考
1. Route Files (CRITICAL)
1. 路由文件(关键)
- - page.tsx conventions for rendering UI
files-page-component - - route.ts conventions for API endpoints
files-api-route - - layout.tsx conventions for shared UI wrappers
files-layout - - middleware.ts conventions for request processing
files-middleware - - error.tsx conventions for error handling
files-error-boundary - - not-found.tsx conventions for 404 pages
files-not-found-boundary
- - 用于渲染UI的page.tsx规范
files-page-component - - 用于API端点的route.ts规范
files-api-route - - 用于共享UI包裹层的layout.tsx规范
files-layout - - 用于请求处理的middleware.ts规范
files-middleware - - 用于错误处理的error.tsx规范
files-error-boundary - - 用于404页面的not-found.tsx规范
files-not-found-boundary
2. Dynamic Parameters (HIGH)
2. 动态参数(高)
- - [id] syntax for single dynamic segments
params-dynamic-segments - - [...slug] syntax for catch-all routes
params-catch-all - - (group) syntax for layout grouping without URL impact
params-route-groups
- - 单个动态路由段的[id]语法
params-dynamic-segments - - 通配符路由的[...slug]语法
params-catch-all - - 不影响URL的布局分组((group))语法
params-route-groups
3. Data Loading (HIGH)
3. 数据加载(高)
- - loader() function for server-side data fetching
data-loader - - action() function for form submissions and mutations
data-action - - NotFoundError/RedirectError for flow control
data-error-control-flow - - getContext(), get(), set() for request-scoped data
data-context-api
- - 用于服务端数据获取的
data-loader函数loader() - - 用于表单提交和变更处理的
data-action函数action() - - 用于流程控制的NotFoundError/RedirectError
data-error-control-flow - - 用于请求作用域数据的getContext()、get()、set()方法
data-context-api
How to Use
使用方法
Read individual rule files for detailed explanations and code examples:
rules/files-page-component.md
rules/data-loader.mdEach rule file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and references
阅读单个规则文件以获取详细说明和代码示例:
rules/files-page-component.md
rules/data-loader.md每个规则文件包含:
- 规则重要性的简要说明
- 错误代码示例及解释
- 正确代码示例及解释
- 额外背景信息及参考资料