react-router
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseReact Router
React Router
React Router is mode-specific. Before changing an app, identify the mode, load the matching reference, then read the installed docs for the installed package version.
React Router是模式特定的。在修改应用之前,请先确定模式,加载对应的参考文档,然后阅读已安装包版本的本地文档。
Identify the Mode
确定模式
Do not apply Framework/Data patterns to a Declarative app unless you are intentionally migrating modes.
请勿将Framework/Data模式的模式应用到Declarative模式应用中,除非你有意进行模式迁移。
Framework Mode
Framework模式
Use Framework Mode guidance when you see:
- in dependencies
@react-router/dev react-router.config.tsapp/routes.ts- and/or
app/entry.server.tsxfilesapp/entry.client.tsx - route modules under
app/routes/ - route exports like ,
loader,action,clientLoader,clientAction,ErrorBoundary,meta, orlinksheaders - imports from
./+types/... - the React Router Vite plugin from
@react-router/dev/vite
Framework examples usually use the default directory, but check for a custom before assuming exact paths.
app/react-router.config.tsappDirectoryThen read .
references/framework-mode.md当你看到以下特征时,请遵循Framework模式的指导:
- 依赖中包含
@react-router/dev - 存在文件
react-router.config.ts - 存在文件
app/routes.ts - 存在和/或
app/entry.server.tsx文件app/entry.client.tsx - 目录下的路由模块
app/routes/ - 路由导出项如、
loader、action、clientLoader、clientAction、ErrorBoundary、meta或linksheaders - 从导入的内容
./+types/... - 来自的React Router Vite插件
@react-router/dev/vite
Framework模式的示例通常使用默认的目录,但在假设路径之前,请检查中的自定义配置。
app/react-router.config.tsappDirectory之后请阅读。
references/framework-mode.mdData Mode
Data模式
Use Data Mode guidance when you see:
- ,
createBrowserRouter,createHashRouter, orcreateMemoryRoutercreateStaticRouter <RouterProvider router={router}>- route objects with properties like ,
path,children,loader,action,Component, orErrorBoundarylazy - data APIs without the Framework Vite plugin
Then read .
references/data-mode.md当你看到以下特征时,请遵循Data模式的指导:
- 使用、
createBrowserRouter、createHashRouter或createMemoryRoutercreateStaticRouter - 使用
<RouterProvider router={router}> - 包含、
path、children、loader、action、Component或ErrorBoundary等属性的路由对象lazy - 未使用Framework Vite插件的数据API
之后请阅读。
references/data-mode.mdDeclarative Mode
Declarative模式
Use Declarative Mode guidance when you see:
- ,
<BrowserRouter>, or<HashRouter><MemoryRouter> - and
<Routes>JSX route configuration<Route> - route components passed with
element={<Component />} - no data router, no route module convention, and no loaders/actions
Then read .
references/declarative-mode.md当你看到以下特征时,请遵循Declarative模式的指导:
- 使用、
<BrowserRouter>或<HashRouter><MemoryRouter> - 使用和
<Routes>的JSX路由配置<Route> - 通过传递路由组件
element={<Component />} - 无数据路由、无路由模块约定、无加载器/动作
之后请阅读。
references/declarative-mode.mdRSC Framework and RSC Data Modes
RSC Framework和RSC Data模式
React Server Components support is unstable and exists in both Framework and Data variants. Use RSC guidance when you see:
unstable_reactRouterRSC@vitejs/plugin-rscunstable_RSCRouteConfig- RSC entry files such as
entry.rsc - ,
ServerComponent,ServerErrorBoundary, orServerLayoutServerHydrateFallback - React directives or boundary packages such as ,
"use client", or"server-only""client-only"
For RSC Framework, read both and .
For RSC Data, read both and .
references/framework-mode.mdreferences/rsc.mdreferences/data-mode.mdreferences/rsc.mdReact Server Components的支持尚不稳定,且存在Framework和Data两种变体。当你看到以下特征时,请遵循RSC相关指导:
- 使用
unstable_reactRouterRSC - 使用
@vitejs/plugin-rsc - 使用
unstable_RSCRouteConfig - 存在RSC入口文件如
entry.rsc - 使用、
ServerComponent、ServerErrorBoundary或ServerLayoutServerHydrateFallback - React指令或边界包如、
"use client"或"server-only""client-only"
对于RSC Framework模式,请同时阅读和。
对于RSC Data模式,请同时阅读和。
references/framework-mode.mdreferences/rsc.mdreferences/data-mode.mdreferences/rsc.mdUse Installed Docs as Source of Truth
以已安装文档为权威来源
React Router ships markdown docs in the package so guidance can match the installed version:
txt
node_modules/react-router/docs/Key docs paths:
txt
node_modules/react-router/docs/index.md
node_modules/react-router/docs/start/
node_modules/react-router/docs/how-to/
node_modules/react-router/docs/explanation/
node_modules/react-router/docs/upgrading/When this skill references , read the matching file under . If the installed version does not include local docs, use the repo directory when working inside the React Router repository; in a consuming app, fall back to version-matched website docs.
react-router/docs/...node_modules/react-router/docs/docs/Most docs include a mode marker near the top:
txt
[MODES: framework, data, declarative]Only apply a doc when its mode marker matches the app mode. If a task spans modes, prefer the section or file that matches the current app.
RSC is documented primarily in:
txt
node_modules/react-router/docs/how-to/react-server-components.mdReact Router在包中附带了Markdown文档,以便指导内容与已安装版本匹配:
txt
node_modules/react-router/docs/关键文档路径:
txt
node_modules/react-router/docs/index.md
node_modules/react-router/docs/start/
node_modules/react-router/docs/how-to/
node_modules/react-router/docs/explanation/
node_modules/react-router/docs/upgrading/当本技能引用时,请阅读下对应的文件。如果已安装版本不包含本地文档,在React Router仓库内工作时请使用仓库的目录;在消费应用中,请回退到版本匹配的官网文档。
react-router/docs/...node_modules/react-router/docs/docs/大多数文档顶部附近包含模式标记:
txt
[MODES: framework, data, declarative]仅当文档的模式标记与应用模式匹配时,才应用该文档的指导。如果任务涉及多种模式,请优先选择与当前应用匹配的章节或文件。
RSC相关内容主要记录在:
txt
node_modules/react-router/docs/how-to/react-server-components.mdSkill References
技能参考文档
Load the relevant reference after identifying the mode:
| Reference | Use When |
|---|---|
| Framework Mode or RSC Framework base behavior |
| Data Mode or RSC Data base behavior |
| Declarative Mode |
| Any unstable RSC app |
确定模式后,请加载对应的参考文档:
| 参考文档 | 使用场景 |
|---|---|
| Framework模式或RSC Framework基础行为 |
| Data模式或RSC Data基础行为 |
| Declarative模式 |
| 任何不稳定的RSC应用 |
Mode Migration Doc Index
模式迁移文档索引
If the user explicitly asks to switch modes, read the target mode reference plus the migration-relevant docs:
| Migration | Docs to read |
|---|---|
| Declarative → Data | |
| Declarative/Data → Framework | |
| Framework SPA/SSR/pre-render changes | |
| Future flags/upgrades | |
如果用户明确要求切换模式,请阅读目标模式的参考文档以及与迁移相关的文档:
| 迁移方向 | 需要阅读的文档 |
|---|---|
| Declarative → Data | |
| Declarative/Data → Framework | |
| Framework SPA/SSR/预渲染变更 | |
| 未来特性标识/升级 | |