react-router-v7
Installation
SKILL.md
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.