DocsPluginsShowcaseReleases
npmStar us on GitHub

Getting Started

IntroductionInstallationProject StructureLayouts and PagesLinking and Navigating

Routing

Folder-Based RoutingFile-Based RoutingDynamic RoutesParallel RoutesIntercepting RoutesCatch-All RoutesMDX & Markdown Pages

Special Files

Loading UIError BoundariesTemplateDefaultNot Found

Data Fetching

LoadersActionsAccessing Route Data

Metadata

Metadata & SEOOpen Graph & TwitterIcons & Favicons

API Routes

API Routes OverviewPlain Function HandlersHono IntegrationDynamic API Routes

Environment Variables

OverviewPrefixes & Client ExposureUsing in API Routes

Styling

CSS OverviewTailwind CSSCSS Modules

Platforms

WebWindowsmacOSLinuxAndroidiOS

Deployment

Deployment OverviewProduction ServerStatic ExportHosting Providers

A native React framework for building cross-platform applications from a single codebase.

Resources

  • Documentation
  • Plugins
  • Showcase
  • Releases

Community

  • GitHub Discussions
  • Reddit
  • Discord
  • LinkedIn

More

  • npm
  • GitHub
  • Issues
  • License

© 2026 Bini Cooperation.

Accessing Route Data

Experimental

Read loader, action, and navigation data with the React Router data hooks.

Overview

Once a loader or action runs, React Router stores the result on the matching route. You read it with a hook. Each hook is designed for a specific scope - the current route, another route by id, the whole matched chain, or the current navigation state.

HookScopeCommon use
useLoaderData()Current routePage-level data from a loader
useActionData()Current routeForm submission result
useRouteLoaderData(id)A specific route by idParent loader data in a child
useMatches()Every matched routeBreadcrumbs, analytics
useNavigation()Global navigation statePending/loading states
All of these hooks are auto-imported from react-router-dom inside files under src/app/. In .mdx and .md files you must import them explicitly.

useLoaderData

Returns the resolved value of the current route's loader. Use this inside the page component that defines the loader.

src/app/users/page.tsx
export async function loader() {
  const res = await fetch('/api/users')
  return res.json()
}

export default function Users() {
  const users = useLoaderData()
  return (
    <ul>
      {users.map((u) => (
        <li key={u.id}>{u.name}</li>
      ))}
    </ul>
  )
}

useActionData

Returns the resolved value of the current route's action. It is undefined until the action has run at least once.

src/app/contact/page.tsx
import { Form } from 'react-router-dom'

export async function action({ request }: { request: Request }) {
  const formData = await request.formData()
  const email = formData.get('email')
  return { ok: true, email }
}

export default function Contact() {
  const result = useActionData()
  return (
    <Form method="post">
      <input name="email" type="email" required />
      <button type="submit">Send</button>
      {result?.ok && <p>Thanks, {result.email}!</p>}
    </Form>
  )
}

useRouteLoaderData

Returns the loader value of a route by its route id. Use this in a child component that needs the loader data from a parent layout without re-fetching it.

app
dashboard
layout.tsx
settings
page.tsx
/dashboard/settings
src/app/dashboard/settings/page.tsx
export default function Settings() {
  // Route ids follow the file path inside src/app
  const data = useRouteLoaderData('dashboard')
  return <p>Welcome, {data?.user.name}</p>
}
The route id is derived from the file path. A loader exported from src/app/dashboard/layout.tsx is available under the id dashboard.

useMatches

Returns an array of every route in the current matched chain, each with its handle and data. Use this for breadcrumbs, analytics, or any component that needs to know the full URL hierarchy.

src/app/blog/[slug]/page.tsx
export const handle = { breadcrumb: 'Post' }

export async function loader() {
  const res = await fetch('/api/post')
  return res.json()
}

export default function Post() {
  const matches = useMatches()
  const crumbs = matches.filter((m) => m.handle?.breadcrumb)
  return (
    <nav>
      {crumbs.map((m) => (
        <span key={m.id}>{m.handle.breadcrumb}</span>
      ))}
    </nav>
  )
}

useNavigation

Returns the current global navigation state. Useful for disabling buttons during a submission or showing a top-level loading bar.

StateMeaning
idleNo navigation is happening
loadingA loader is running for the target route
submittingAn action is running (form submission)
src/app/contact/page.tsx
import { Form } from 'react-router-dom'

export default function Contact() {
  const navigation = useNavigation()
  const submitting = navigation.state === 'submitting'

  return (
    <Form method="post">
      <input name="email" type="email" required />
      <button type="submit" disabled={submitting}>
        {submitting ? 'Sending…' : 'Send'}
      </button>
    </Form>
  )
}

Loaders

Fetch data before a route renders.

Actions

Handle form submissions and mutations.

Error Boundaries

Catch render errors and show a fallback UI.

Loading UI

Show a fallback while pages and layouts load.

Layouts and Pages

Create your first pages and wrap them in shared layouts.

Deployment

Deploy to Node, Vercel, Netlify, Cloudflare, or Deno, or build native apps in CI.

Was this helpful?
PreviousActions
NextMetadata

On this page

  • Overview
  • useLoaderData
  • useActionData
  • useRouteLoaderData
  • useMatches
  • useNavigation
Edit this page on GitHub

Accessing Route Data

Experimental

Read loader, action, and navigation data with the React Router data hooks.

Overview

Once a loader or action runs, React Router stores the result on the matching route. You read it with a hook. Each hook is designed for a specific scope - the current route, another route by id, the whole matched chain, or the current navigation state.

HookScopeCommon use
useLoaderData()Current routePage-level data from a loader
useActionData()Current routeForm submission result
useRouteLoaderData(id)A specific route by idParent loader data in a child
useMatches()Every matched routeBreadcrumbs, analytics
useNavigation()Global navigation statePending/loading states
All of these hooks are auto-imported from react-router-dom inside files under src/app/. In .mdx and .md files you must import them explicitly.

useLoaderData

Returns the resolved value of the current route's loader. Use this inside the page component that defines the loader.

src/app/users/page.tsx
export async function loader() {
  const res = await fetch('/api/users')
  return res.json()
}

export default function Users() {
  const users = useLoaderData()
  return (
    <ul>
      {users.map((u) => (
        <li key={u.id}>{u.name}</li>
      ))}
    </ul>
  )
}

useActionData

Returns the resolved value of the current route's action. It is undefined until the action has run at least once.

src/app/contact/page.tsx
import { Form } from 'react-router-dom'

export async function action({ request }: { request: Request }) {
  const formData = await request.formData()
  const email = formData.get('email')
  return { ok: true, email }
}

export default function Contact() {
  const result = useActionData()
  return (
    <Form method="post">
      <input name="email" type="email" required />
      <button type="submit">Send</button>
      {result?.ok && <p>Thanks, {result.email}!</p>}
    </Form>
  )
}

useRouteLoaderData

Returns the loader value of a route by its route id. Use this in a child component that needs the loader data from a parent layout without re-fetching it.

app
dashboard
layout.tsx
settings
page.tsx
/dashboard/settings
src/app/dashboard/settings/page.tsx
export default function Settings() {
  // Route ids follow the file path inside src/app
  const data = useRouteLoaderData('dashboard')
  return <p>Welcome, {data?.user.name}</p>
}
The route id is derived from the file path. A loader exported from src/app/dashboard/layout.tsx is available under the id dashboard.

useMatches

Returns an array of every route in the current matched chain, each with its handle and data. Use this for breadcrumbs, analytics, or any component that needs to know the full URL hierarchy.

src/app/blog/[slug]/page.tsx
export const handle = { breadcrumb: 'Post' }

export async function loader() {
  const res = await fetch('/api/post')
  return res.json()
}

export default function Post() {
  const matches = useMatches()
  const crumbs = matches.filter((m) => m.handle?.breadcrumb)
  return (
    <nav>
      {crumbs.map((m) => (
        <span key={m.id}>{m.handle.breadcrumb}</span>
      ))}
    </nav>
  )
}

useNavigation

Returns the current global navigation state. Useful for disabling buttons during a submission or showing a top-level loading bar.

StateMeaning
idleNo navigation is happening
loadingA loader is running for the target route
submittingAn action is running (form submission)
src/app/contact/page.tsx
import { Form } from 'react-router-dom'

export default function Contact() {
  const navigation = useNavigation()
  const submitting = navigation.state === 'submitting'

  return (
    <Form method="post">
      <input name="email" type="email" required />
      <button type="submit" disabled={submitting}>
        {submitting ? 'Sending…' : 'Send'}
      </button>
    </Form>
  )
}

Loaders

Fetch data before a route renders.

Actions

Handle form submissions and mutations.

Error Boundaries

Catch render errors and show a fallback UI.

Loading UI

Show a fallback while pages and layouts load.

Layouts and Pages

Create your first pages and wrap them in shared layouts.

Deployment

Deploy to Node, Vercel, Netlify, Cloudflare, or Deno, or build native apps in CI.

Was this helpful?
PreviousActions
NextMetadata

On this page

  • Overview
  • useLoaderData
  • useActionData
  • useRouteLoaderData
  • useMatches
  • useNavigation
Edit this page on GitHub