existential-birds/beagle / plugins/beagle-react/skills/react-router-v7
react-router-v7
VerifiedReact 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.
| File | Kind | Size |
|---|---|---|
| ACTIONS.md | markdown | 4.1 KB |
| ADVANCED.md | markdown | 4.0 KB |
| LOADERS.md | markdown | 2.1 KB |
| NAVIGATION.md | markdown | 2.7 KB |
| SKILL.md | skill md | 4.0 KB |
| references/actions.md | markdown | 4.6 KB |
| references/advanced.md | markdown | 5.2 KB |
| references/loaders.md | markdown | 2.4 KB |
| references/navigation.md | markdown | 3.1 KB |
LOADERS.md
View on GitHub# Data Loading Patterns
## Basic Loader
```tsx
{
path: "/teams/:teamId",
loader: async ({ params, request }) => {
const url = new URL(request.url);
const query = url.searchParams.get("q");
const team = await fetchTeam(params.teamId, query);
return { team, name: team.name };
},
Component: Team,
}
function Team() {
const data = useLoaderData();
return <h1>{data.name}</h1>;
}
```
## Parallel Data Loading
Nested routes load data in parallel automatically:
```tsx
createBrowserRouter([
{
path: "/",
loader: rootLoader, // Loads in parallel
children: [
{
path: "project/:id",
loader: projectLoader, // Loads in parallel with rootLoader
},
],
},
]);
```
## Search Params in Loaders
```tsx
{
path: "/search",
loader: async ({ request }) => {
const url = new URL(request.url);
const query = url.searchParams.get("q");
const page = url.searchParams.get("page") || "1";
return { results: await search(query, parseInt(page)) };
},
}
function SearchPage() {
const { results } = useLoaderData();
return (
<Form method="get">
<input type="text" name="q" />
<button type="submit">Search</button>
</Form>
);
}
```
## useSearchParams Hook
```tsx
import { useSearchParams } from "react-router";
function SearchPage() {
const [searchParams, setSearchParams] = useSearchParams();
const query = searchParams.get("q");
return (
<input
value={query || ""}
onChange={(e) => setSearchParams({ q: e.target.value })}
/>
);
}
```
## Revalidation Control
```tsx
function shouldRevalidate({ currentUrl, nextUrl, formAction }) {
return currentUrl.pathname !== nextUrl.pathname;
}
createBrowserRouter([
{
path: "/data",
shouldRevalidate,
loader: dataLoader,
},
]);
```
## Framework Mode Loaders
```tsx
// product.tsx
import { Route } from "./+types/product";
export async function loader({ params }: Route.LoaderArgs) {
const product = await getProduct(params.pid);
return { product };
}
export default function Product({ loaderData }: Route.ComponentProps) {
return <div>{loaderData.product.name}</div>;
}
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |