react-router-v7
БесплатноБез исполняемых скриптовНе проверенReact Router v7 framework mode conventions for route modules, data loaders, actions, and progressive enhancement. Use when building file-based routes with…
от Mindrally★ 323 звезды на GitHubОб этом скилле
React Router v7
React Router v7 framework mode unifies routing, data loading, and mutations into route modules, each exporting a loader, action, default component, and ErrorBoundary for a single URL segment.
Workflow for Building a Route Module
- Create the route file — Add a file under
app/routes/(or your configured routes directory) for the URL segment, using nested folders/files for layouts and dynamic segments. - Export a loader — Fetch the data the route needs before render; validate route params and search params at the top of the loader.
- Export a component — Read loader data via
useLoaderData()and render UI; keep the component focused on presentation. - Export an action — Handle
POST/PUT/DELETEsubmissions from<Form>oruseFetcher; return typed data (including validation errors) instead of throwing for expected failures. - Export an ErrorBoundary — Handle thrown errors (400s, 500s, unexpected exceptions) locally so one route's failure doesn't take down the whole app.
- Wire up navigation — Use
<Form>,useFetcher, anduseSubmitfor mutations so the app works with JavaScript disabled and gets optimistic UI when it's enabled. - Test the module — Write tests for the loader, action, validation failures, and error boundary independently of the rendered component tree.
Route Modules
- Use route modules as the boundary for route UI, loader data, actions, metadata, and error boundaries — a route module is the unit of code splitting and data loading.
- Keep route modules small; move shared UI to
app/components/and reusable data access to a services layer (e.g.app/services/posts.server.ts). - Prefer file-based routing in framework mode when the project is configured for it; use the explicit
routes.tsconfig for advanced/dynamic route trees. - Use nested routes for shared layouts and progressive disclosure — a parent route's
<Outlet />renders the matched child. - Export route-specific
ErrorBoundarycomponents for recoverable route failures instead of relying on a single app-wide boundary.
// app/routes/posts.$postId.tsx
import { Form, useLoaderData, useNavigation } from "react-router";
import type { Route } from "./+types/posts.$postId";
import { getPost, updatePost } from "~/services/posts.server";
export async function loader({ params }: Route.LoaderArgs) {
const post = await getPost(params.postId);
if (!post) {
throw new Response("Not Found", { status: 404 });
}
return { post };
}
export async function action({ request, params }: Route.ActionArgs) {
const formData = await request.formData();
const title = String(formData.get("title") ?? "");
if (title.trim().length === 0) {
return { ok: false as const, errors: { title: "Title is required" } };
}
await updatePost(params.postId, { title });
return { ok: true as const, errors: null };
}
export default function PostDetail() {
const { post } = useLoaderData<typeof loader>();
const navigation = useNavigation();
const isSubmitting = navigation.state === "submitting";
return (
<Form method="post">
<input name="title" defaultValue={post.title} />
<button type="submit" disabled={isSubmitting}>
{isSubmitting ? "Saving..." : "Save"}
</button>
</Form>
);
}
export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
if (error instanceof Response && error.status === 404) {
return <p>Post not found.</p>;
}
return <p>Something went wrong loading this post.</p>;
}
Data Loading
- Use loaders for route data that should be available before render — this avoids loading spinners for data the page can't function without.
- Keep loaders deterministic and side-effect free; a loader should read data, not write it.
- Validate params and search params at the loader boundary (e.g. parse and range-check a
pagequery param) rather than trusting them downstream. - Return typed data and consume it through
useLoaderData<typeof loader>()rather than duplicating fetch logic in the component. - Use deferred or streaming patterns (
defer, or returning promises for<Await>) only when they measurably improve perceived performance — not by default.
Mutations
- Use actions for route mutations and form submissions; an action runs on
POST/PUT/PATCH/DELETEnavigations and fetcher submissions to that route. - Prefer
<Form>,useFetcher, anduseSubmitfor progressive enhancement — these work without client-side JavaScript and layer on optimistic UI when it's available. - Revalidate affected loader data after mutations; React Router automatically revalidates loaders on the current route tree after an action completes, so avoid manually refetching in
useEffect. - Handle validation errors as typed action data (
return { errors }) instead of throwing generic exceptions — reserve thrownResponses for actual HTTP-status failures (404, 401, 500). - Keep server-only secrets and p
Установить react-router-v7 в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл react-router-v7?
React Router v7 framework mode conventions for route modules, data loaders, actions, and progressive enhancement. Use when building file-based routes with loaders/actions, handling form submissions with Form/useFetcher/useSubmit, adding route ErrorBoundary components, revalidating data after mutations, or migrating Remix-style route modules to React Router v7.
Как установить скилл react-router-v7?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл react-router-v7 запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic