Skip to main content

Quick Start Guide

Get started with React Router by building a simple application in your preferred mode.

Framework Mode Quick Start

Build a type-safe, full-stack app with automatic code splitting and SSR.
1

Create project structure

Create the following files:
my-app/
├── app/
│   ├── root.tsx
│   ├── routes.ts
│   └── routes/
│       └── _index.tsx
├── vite.config.ts
└── package.json
2

Configure routes

Define your routes in app/routes.ts:
app/routes.ts
import { type RouteConfig } from "@react-router/dev/routes";
import { flatRoutes } from "@react-router/fs-routes";

export default flatRoutes() satisfies RouteConfig;
3

Create root layout

Set up your app shell in app/root.tsx:
app/root.tsx
import {
  Links,
  Meta,
  Outlet,
  Scripts,
  ScrollRestoration,
} from "react-router";

export function Layout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <head>
        <meta charSet="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <Meta />
        <Links />
      </head>
      <body>
        {children}
        <ScrollRestoration />
        <Scripts />
      </body>
    </html>
  );
}

export default function App() {
  return <Outlet />;
}
4

Create index route

Add your first route with a loader in app/routes/_index.tsx:
app/routes/_index.tsx
import type { Route } from "./+types/_index";

export function loader({ params }: Route.LoaderArgs) {
  return { message: "Hello, React Router!" };
}

export default function Index({ loaderData }: Route.ComponentProps) {
  return (
    <div>
      <h1>{loaderData.message}</h1>
      <p>Welcome to Framework Mode</p>
    </div>
  );
}
5

Run your app

Start the development server:
npm run dev
Open http://localhost:5173 to see your app!
Framework Mode automatically generates TypeScript types in .react-router/types/ for full type safety across your routes.

Add More Routes

Create additional routes using file-based routing conventions:
app/routes/about.tsx
import type { Route } from "./+types/about";

export default function About() {
  return <h1>About Page</h1>;
}
app/routes/blog.$slug.tsx
import type { Route } from "./+types/blog.$slug";

export function loader({ params }: Route.LoaderArgs) {
  return { slug: params.slug };
}

export default function BlogPost({ loaderData }: Route.ComponentProps) {
  return <h1>Blog Post: {loaderData.slug}</h1>;
}

Comparison at a Glance

FeatureFramework ModeData ModeDeclarative Mode
Setup ComplexityHighMediumLow
Type Safety✅ Auto-generated⚠️ Manual⚠️ Manual
Data Loading✅ Loaders & Actions✅ Loaders & Actions❌ Client-side only
Code Splitting✅ Automatic⚠️ Manual⚠️ Manual
SSR Support✅ Built-in⚠️ Manual setup⚠️ Manual setup
Best ForFull-stack appsSPAs with dataSimple client apps

Next Steps

Routing Concepts

Learn about nested routes, layouts, and navigation

Data Loading

Master loaders, actions, and data mutations

Type Safety

Set up end-to-end type safety in Framework Mode

Deployment

Deploy your React Router app to production

Build docs developers (and LLMs) love