All skills
remix-run avatar

/react-router-framework-mode

@220978e
by Remixremix-run/agent-skills136 stars
4

Build full-stack React applications using React Router's framework mode. Use when configuring routes, working with loaders and actions, handling forms, handling navigation, pending/optimistic UI, error boundaries, or working with react-router.config.ts or other react router conventions.

Use this Skill: https://skilld.dev/gh/remix-run/agent-skills/react-router-framework-mode

This session only. Nothing lands on disk.

referencesrouting.md

≈1.5k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Routing

For file conventions (root.tsx, routes.ts, etc.), see special-files.md.

If using @react-router/fs-routes see https://reactrouter.com/how-to/file-route-conventions

Route Configuration

Routes are configured in app/routes.ts. Each route has a URL pattern and a file path to the route module:

import { type RouteConfig, route } from "@react-router/dev/routes";

export default [
  route("some/path", "./some/file.tsx"),
  // pattern ^           ^ module file
] satisfies RouteConfig;

Complete Example

import {
  type RouteConfig,
  route,
  index,
  layout,
  prefix,
} from "@react-router/dev/routes";

export default [
  index("./home.tsx"),
  route("about", "./about.tsx"),

  layout("./auth/layout.tsx", [
    route("login", "./auth/login.tsx"),
    route("register", "./auth/register.tsx"),
  ]),

  ...prefix("concerts", [
    index("./concerts/home.tsx"),
    route(":city", "./concerts/city.tsx"),
    route("trending", "./concerts/trending.tsx"),
  ]),
] satisfies RouteConfig;

Combining with File-Based Routes

import { type RouteConfig, route } from "@react-router/dev/routes";
import { flatRoutes } from "@react-router/fs-routes";

export default [
  route("/", "./home.tsx"),
  ...(await flatRoutes()),
] satisfies RouteConfig;

Route Helpers

Helper Purpose Adds URL segment?
route(path, file, children?) Standard route Yes
index(file) Default child route No
layout(file, children) Shared UI wrapper No
prefix(path, children) Path prefix only Yes

Nested Routes

Child routes are passed as the third argument:

export default [
  route("dashboard", "./dashboard.tsx", [
    index("./dashboard-home.tsx"),
    route("settings", "./dashboard-settings.tsx"),
  ]),
] satisfies RouteConfig;

Parent path is automatically included: creates /dashboard and /dashboard/settings.

Outlet

Child routes render through <Outlet /> in the parent:

import { Outlet } from "react-router";

export default function Dashboard() {
  return (
    <div>
      <h1>Dashboard</h1>
      <Outlet />
    </div>
  );
}

Root Route

Every route in routes.ts is nested inside app/root.tsx. Put global navigation, footer, providers, and fonts there.

See special-files.md for root.tsx customization patterns.

Layout Routes (Use Them!)

Prefer nested routes over flat structures. Layouts reduce code duplication and enable shared UI.

Create nesting without adding URL segments:

export default [
  layout("./marketing/layout.tsx", [
    index("./marketing/home.tsx"), // renders at /
    route("contact", "./marketing/contact.tsx"), // renders at /contact
  ]),
] satisfies RouteConfig;

Both routes render into marketing/layout.tsx's <Outlet />.

Anti-Pattern: Flat Routes

// ❌ DON'T: Flat structure with no shared layouts
export default [
  route("dashboard", "./dashboard.tsx"),
  route("dashboard/settings", "./dashboard-settings.tsx"),
  route("dashboard/profile", "./dashboard-profile.tsx"),
] satisfies RouteConfig;

// ✅ DO: Use nested routes with shared layout
export default [
  route("dashboard", "./dashboard/layout.tsx", [
    index("./dashboard/index.tsx"),
    route("settings", "./dashboard/settings.tsx"),
    route("profile", "./dashboard/profile.tsx"),
  ]),
] satisfies RouteConfig;

Index Routes

Render at the parent's URL (default child):

export default [
  index("./home.tsx"), // renders at /
  route("dashboard", "./dashboard.tsx", [
    index("./dashboard-home.tsx"), // renders at /dashboard
    route("settings", "./settings.tsx"), // renders at /dashboard/settings
  ]),
] satisfies RouteConfig;

Index routes cannot have children.

Route Prefixes

Add a path prefix without introducing a parent route:

export default [
  ...prefix("projects", [
    index("./projects/home.tsx"), // /projects
    route(":pid", "./projects/project.tsx"), // /projects/:pid
  ]),
] satisfies RouteConfig;

Equivalent to:

export default [
  route("projects", "./projects/home.tsx"),
  route("projects/:pid", "./projects/project.tsx"),
] satisfies RouteConfig;

Dynamic Segments

Segments starting with : are dynamic and available via params:

route("teams/:teamId", "./team.tsx");
import type { Route } from "./+types/team";

export async function loader({ params }: Route.LoaderArgs) {
  // params.teamId is typed as string
  return fetchTeam(params.teamId);
}

export default function Team({ params }: Route.ComponentProps) {
  return <h1>Team {params.teamId}</h1>;
}

Multiple dynamic segments:

route("c/:categoryId/p/:productId", "./product.tsx");
// params: { categoryId: string; productId: string }

Optional Segments

Add ? to make a segment optional:

route(":lang?/categories", "./categories.tsx");
// matches /categories and /en/categories

route("users/:userId/edit?", "./user.tsx");
// matches /users/123 and /users/123/edit

Splats (Catch-All)

Match any remaining path with /*:

route("files/*", "./files.tsx");
export async function loader({ params }: Route.LoaderArgs) {
  const filePath = params["*"]; // e.g., "docs/intro.md"
  return getFile(filePath);
}

// Destructure with rename
const { "*": splat } = params;

404 Catch-All

route("*", "./catchall.tsx");
export function loader() {
  throw new Response("Page not found", { status: 404 });
}

See Also

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill is a comprehensive documentation reference for building applications with React Router's framework mode. It provides standard architectural patterns, code examples, and best practices for routing, data loading, actions, and session management. No security risks or malicious patterns were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    2/13 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 220978e. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Steadyupdated 8 months ago

README badge

README badge for remix-run/agent-skills/react-router-framework-mode