react-router-v7 by existential-birds/beagle
npx skills add https://github.com/existential-birds/beagle --skill react-router-v7路由器设置(数据模式):
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(<RouterProvider router={router} />);
框架模式(Vite 插件):
// routes.ts
import { index, route } from "@react-router/dev/routes";
export default [
index("./home.tsx"),
route("products/:pid", "./product.tsx"),
];
createBrowserRouter([
{
path: "/dashboard",
Component: Dashboard,
children: [
{ index: true, Component: DashboardHome },
{ path: "settings", Component: Settings },
],
},
]);
function Dashboard() {
return (
<div>
<h1>Dashboard</h1>
<Outlet /> {/* 渲染子路由 */}
</div>
);
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
{ path: "teams/:teamId" } // params.teamId
{ path: ":lang?/categories" } // 可选片段
{ path: "files/*" } // 通配符: params["*"]
使用 <Form>:创建/删除操作并伴随 URL 变化,添加到历史记录
使用 useFetcher:内联更新、列表操作、弹出框 - 不改变 URL
使用 loader:渲染前获取数据,服务端获取,自动重新验证 使用 useEffect:仅客户端数据,依赖用户交互,订阅
| 功能 | 框架模式 | 数据模式 | 声明式模式 |
|---|---|---|---|
| 设置 | Vite 插件 | createBrowserRouter | <BrowserRouter> |
| 类型安全 | 自动生成类型 | 手动 | 手动 |
| SSR 支持 | 内置 | 手动 | 有限 |
| 使用场景 | 全栈应用 | 需要控制的 SPA | 简单/遗留应用 |
每周安装量
231
代码仓库
GitHub 星标数
40
首次出现
2026年1月20日
安全审计
安装于
opencode170
gemini-cli166
github-copilot165
codex161
cursor133
claude-code125
Router Setup (Data Mode) :
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(<RouterProvider router={router} />);
Framework Mode (Vite plugin) :
// routes.ts
import { index, route } from "@react-router/dev/routes";
export default [
index("./home.tsx"),
route("products/:pid", "./product.tsx"),
];
createBrowserRouter([
{
path: "/dashboard",
Component: Dashboard,
children: [
{ index: true, Component: DashboardHome },
{ path: "settings", Component: Settings },
],
},
]);
function Dashboard() {
return (
<div>
<h1>Dashboard</h1>
<Outlet /> {/* Renders child routes */}
</div>
);
}
{ path: "teams/:teamId" } // params.teamId
{ path: ":lang?/categories" } // Optional segment
{ path: "files/*" } // Splat: params["*"]
Use<Form>: Creating/deleting with URL change, adding to history UseuseFetcher: Inline updates, list operations, popovers - no URL change
Use loader : Data before render, server-side fetch, automatic revalidation Use useEffect : Client-only data, user-interaction dependent, subscriptions
| Feature | Framework Mode | Data Mode | Declarative Mode |
|---|---|---|---|
| Setup | Vite plugin | createBrowserRouter | <BrowserRouter> |
| Type Safety | Auto-generated types | Manual | Manual |
| SSR Support | Built-in | Manual | Limited |
| Use Case | Full-stack apps | SPAs with control | Simple/legacy |
Weekly Installs
231
Repository
GitHub Stars
40
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode170
gemini-cli166
github-copilot165
codex161
cursor133
claude-code125
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
106,200 周安装