React Router

remix-run/react-router/.agents/skills/react-router

作者 remix-run4fbf6076d44bd832f14bee4b4b1ccfcbc2f5aee6MIT收錄於 2026年10月9日更新於 2026年10月9日

Build applications with React Router in Framework, Data, Declarative, and unstable RSC modes. Use when configuring routes, route modules, loaders, actions, forms, fetchers, navigation, pending UI, SSR/SPA/pre-rendering, middleware, URL params/search params, or React Router upgrades.

AI 產生的概覽

指導在 Framework、Data、Declarative 及不穩定的 RSC 模式下建置 React Router 應用程式。

功能
此技能協助代理判斷應用程式使用哪一種 React Router 模式,再載入對應的參考檔案。內容涵蓋路由設定、路由模組、loader、action、表單、fetcher、導覽、等待介面、渲染策略、中介軟體、URL 參數以及升級。它引導代理以已安裝套件的文件為準,並提供模式移轉的文件索引。
適用情境
適用於處理 React Router 應用程式,且需要針對路由、資料載入、action、渲染或升級的模式化指引時。也用於模式移轉,例如從 Declarative 移轉到 Data 或 Framework 模式。
執行需求
需要一個已安裝 React Router 套件的專案,以便讀取 node_modules/react-router/docs/ 下隨套件附帶的 markdown 文件。不附帶指令碼,僅為說明與參考檔案。

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.

Identify the Mode

Do not apply Framework/Data patterns to a Declarative app unless you are intentionally migrating modes.

Framework Mode

Use Framework Mode guidance when you see:

  • @react-router/dev in dependencies
  • react-router.config.ts
  • app/routes.ts
  • app/entry.server.tsx and/or app/entry.client.tsx files
  • route modules under app/routes/
  • route exports like loader, action, clientLoader, clientAction, ErrorBoundary, meta, links, or headers
  • imports from ./+types/...
  • the React Router Vite plugin from @react-router/dev/vite

Framework examples usually use the default app/ directory, but check react-router.config.ts for a custom appDirectory before assuming exact paths.

Then read references/framework-mode.md.

Data Mode

Use Data Mode guidance when you see:

  • createBrowserRouter, createHashRouter, createMemoryRouter, or createStaticRouter
  • <RouterProvider router={router}>
  • route objects with properties like path, children, loader, action, Component, ErrorBoundary, or lazy
  • data APIs without the Framework Vite plugin

Then read references/data-mode.md.

Declarative Mode

Use Declarative Mode guidance when you see:

  • <BrowserRouter>, <HashRouter>, or <MemoryRouter>
  • <Routes> and <Route> JSX route configuration
  • route components passed with element={<Component />}
  • no data router, no route module convention, and no loaders/actions

Then read references/declarative-mode.md.

RSC Framework and RSC Data Modes

React Server Components support is unstable and exists in both Framework and Data variants. Use RSC guidance when you see:

  • unstable_reactRouterRSC
  • @vitejs/plugin-rsc
  • unstable_RSCRouteConfig
  • RSC entry files such as entry.rsc
  • ServerComponent, ServerErrorBoundary, ServerLayout, or ServerHydrateFallback
  • React directives or boundary packages such as "use client", "server-only", or "client-only"

For RSC Framework, read both references/framework-mode.md and references/rsc.md. For RSC Data, read both references/data-mode.md and references/rsc.md.

Use 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.mdnode_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 react-router/docs/..., read the matching file under node_modules/react-router/docs/. If the installed version does not include local docs, use the repo docs/ directory when working inside the React Router repository; in a consuming app, fall back to version-matched website 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.md

Skill References

Load the relevant reference after identifying the mode:

ReferenceUse When
references/framework-mode.mdFramework Mode or RSC Framework base behavior
references/data-mode.mdData Mode or RSC Data base behavior
references/declarative-mode.mdDeclarative Mode
references/rsc.mdAny unstable RSC app

Mode Migration Doc Index

If the user explicitly asks to switch modes, read the target mode reference plus the migration-relevant docs:

MigrationDocs to read
Declarative → Datareact-router/docs/start/modes.md, react-router/docs/start/data/routing.md, react-router/docs/start/data/data-loading.md, react-router/docs/start/data/actions.md
Declarative/Data → Frameworkreact-router/docs/start/modes.md, react-router/docs/start/framework/routing.md, react-router/docs/start/framework/route-module.md, react-router/docs/how-to/route-module-type-safety.md
Framework SPA/SSR/pre-render changesreact-router/docs/start/framework/rendering.md, react-router/docs/how-to/spa.md, react-router/docs/how-to/pre-rendering.md, react-router/docs/start/framework/data-loading.md, react-router/docs/start/framework/actions.md
Future flags/upgradesreact-router/docs/upgrading/future.md and relevant files under react-router/docs/upgrading/

來源與署名

來源:remix-run/react-router位於.agents/skills/react-router提交4fbf607

授權條款: MIT

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架