闲社服务运行正常AI智能体自动化平台
r

React路由v7

技能标识:react-router-v7

React Router v7 best practices for data-driven routing. Use when implementing routes, loaders, actions, Form components, fetchers, navigation guards, protected routes, or URL search params. Triggers on createBrowserRouter, RouterProvider, useLoaderData, useActionData, useFetcher, NavLink, Outlet.

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.1.0
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

React路由v7

React Router v7 最佳实践

快速参考

路由器设置(数据模式):
tsx
import { createBrowserRouter, RouterProvider } from react-router;

const router = createBrowserRouter([
{
path: /,
Component: Root,
ErrorBoundary: RootErrorBoundary,
loader: rootLoader,
children: [
{ index: true, Component: Home },
{ path: products/:productId, Component: Product, loader: productLoader },
],
},
]);

ReactDOM.createRoot(root).render();

框架模式(Vite 插件):
ts
// routes.ts
import { index, route } from @react-router/dev/routes;

export default [
index(./home.tsx),
route(products/:pid, ./product.tsx),
];

路由配置

嵌套路由与 Outlet

tsx
createBrowserRouter([
{
path: /dashboard,
Component: Dashboard,
children: [
{ index: true, Component: DashboardHome },
{ path: settings, Component: Settings },
],
},
]);

function Dashboard() {
return (


仪表盘


{/ 渲染子路由 /}

);
}

动态段与通配符

tsx
{ path: teams/:teamId } // params.teamId
{ path: :lang?/categories } // 可选段
{ path: files/ } // 通配符:params[]

关键决策点

Form 与 Fetcher

使用

:创建/删除时改变 URL,添加到历史记录
使用 useFetcher:内联更新、列表操作、弹出框——不改变 URL

Loader 与 useEffect

使用 loader:渲染前获取数据、服务端获取、自动重新验证
使用 useEffect:仅客户端数据、依赖用户交互、订阅

附加文档

模式对比

特性框架模式数据模式声明式模式
设置Vite 插件createBrowserRouter<BrowserRouter>
类型安全
自动生成类型 | 手动 | 手动 | | SSR 支持 | 内置 | 手动 | 有限 | | 使用场景 | 全栈应用 | 可控 SPA | 简单/遗留项目 |

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 react-router-v7-1775977982 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 react-router-v7-1775977982 技能

通过命令行安装

skillhub install react-router-v7-1775977982

下载

⬇ 下载 react-router-v7 v1.1.0(免费)

文件大小: 13.07 KB | 发布时间: 2026-4-13 11:44

v1.1.0 最新 2026-4-13 11:44
- Added comprehensive best practices and quick reference for React Router v7 usage.
- Expanded documentation on route setup, nested routes, dynamic segments, and splats.
- Clarified when to use Forms vs. fetchers, and loader vs. useEffect for data handling.
- Included a mode comparison table covering Framework, Data, and Declarative modes.
- Linked to additional references for data loading, mutations, navigation, and advanced features.
返回顶部