react-router-framework-mode
npx machina-cli add skill andrmaz/spec-driven-architecture/react-router-framework-mode --openclawReact Router Framework Mode
Framework mode is React Router's full-stack development experience with file-based routing, server-side, client-side, and static rendering strategies, data loading and mutations, and type-safe route module API.
When to Apply
- Configuring new routes (
app/routes.ts) - Loading data with
loaderorclientLoader - Handling mutations with
actionorclientAction - Navigating with
<Link>,<NavLink>,<Form>,redirect, anduseNavigate - Implementing pending/loading UI states
- Configuring SSR, SPA mode, or pre-rendering (
react-router.config.ts) - Implementing authentication
References
Load the relevant reference for detailed guidance on the specific API/concept:
| Reference | Use When |
|---|---|
references/routing.md | Configuring routes, nested routes, dynamic segments |
references/route-modules.md | Understanding all route module exports |
references/special-files.md | Customizing root.tsx, adding global nav/footer, fonts |
references/data-loading.md | Loading data with loaders, streaming, caching |
references/actions.md | Handling forms, mutations, validation |
references/navigation.md | Links, programmatic navigation, redirects |
references/pending-ui.md | Loading states, optimistic UI |
references/error-handling.md | Error boundaries, error reporting |
references/rendering-strategies.md | SSR vs SPA vs pre-rendering configuration |
references/middleware.md | Adding middleware (requires v7.9.0+) |
references/sessions.md | Cookie sessions, authentication, protected routes |
references/type-safety.md | Auto-generated route types, type imports, type safety |
Version Compatibility
Some features require specific React Router versions. Always verify before implementing:
npm list react-router
| Feature | Minimum Version | Notes |
|---|---|---|
| Middleware | 7.9.0+ | Requires v8_middleware flag |
| Core framework features | 7.0.0+ | loaders, actions, Form, etc. |
Critical Patterns
These are the most important patterns to follow. Load the relevant reference for full details.
Forms & Mutations
Search forms - use <Form method="get">, NOT onSubmit with setSearchParams:
// ✅ Correct
<Form method="get">
<input name="q" />
</Form>
// ❌ Wrong - don't manually handle search params
<form onSubmit={(e) => { e.preventDefault(); setSearchParams(...) }}>
Inline mutations - use useFetcher, NOT <Form> (which causes page navigation):
const fetcher = useFetcher();
const optimistic = fetcher.formData?.get("favorite") === "true" ?? isFavorite;
<fetcher.Form method="post" action={`/favorites/${id}`}>
<button>{optimistic ? "★" : "☆"}</button>
</fetcher.Form>;
See references/actions.md for complete patterns.
Layouts
Global UI belongs in root.tsx - don't create separate layout files for nav/footer:
// app/root.tsx - add navigation, footer, providers here
export default function App() {
return (
<div>
<nav>...</nav>
<Outlet />
<footer>...</footer>
</div>
);
}
Use nested routes for section-specific layouts. See references/routing.md.
Route Module Exports
meta uses loaderData, not deprecated data:
// ✅ Correct
export function meta({ loaderData }: Route.MetaArgs) { ... }
// ❌ Wrong - `data` is deprecated
export function meta({ data }: Route.MetaArgs) { ... }
See references/route-modules.md for all exports.
Further Documentation
If anything related to React Router is not covered in these references, you can search the official documentation:
Source
git clone https://github.com/andrmaz/spec-driven-architecture/blob/develop/.agents/skills/react-router-framework-mode/SKILL.mdView on GitHub Overview
Framework mode delivers React Router’s full-stack experience, combining file-based routing, SSR/SPA strategies, data loading and mutations, and a type-safe route module API. It enables creating routes with loaders, actions, forms, and authenticated flows across server and client rendering, helping you build scalable, robust apps with strong typing and controlled navigation.
How This Skill Works
Developers define routes and module exports in a route-centric API (e.g., app/routes.ts, react-router.config.ts). Data loading and mutations flow through loader/clientLoader and action/clientAction, while UI components use Link, Form, and useNavigate for navigation; pending UI and error boundaries handle loading states and errors.
When to Use It
- Configuring new routes with app/routes.ts
- Loading data with loader or clientLoader
- Handling mutations with action or clientAction
- Navigating with Link, Form, redirect, and useNavigate
- Configuring SSR, SPA, or pre-rendering with react-router.config.ts
Quick Start
- Step 1: Install and enable framework mode in your project
- Step 2: Create routes in app/routes.ts and, if needed, react-router.config.ts
- Step 3: Add loaders, actions, Form usage, and navigation handlers per references
Best Practices
- Use <Form method="get"> for search forms to avoid manual URL param handling
- Prefer useFetcher for inline mutations to avoid full page navigations
- Place global UI (nav, footer) in root.tsx to avoid separate layout files
- Leverage route modules and type-safety for auto-generated types and exports
- Implement loading states with pending UI and robust error boundaries
Example Use Cases
- Define routes in app/routes.ts and render with Outlet
- Load page data with a loader and display a loading state
- Submit data via an action and handle server responses
- Implement protected routes using sessions and middleware patterns
- Use useFetcher to toggle UI elements with optimistic updates (e.g., favorites)