Skip to main content

loader

A server-side function that loads data for a route before it renders.

Signature

LoaderFunctionArgs
required
Arguments passed to the loader function
Response | Data
Can return:
  • A Response object (with json(), redirect(), etc.)
  • Plain data (automatically serialized)
  • A Promise resolving to either

Basic Example

Returning Responses

Reading Request Data

Using Context

Best Practices

Use the route-specific type for automatic param type inference:
Throw responses or errors to trigger error boundaries:
Only return JSON-serializable data:
Use Promise.all() to load data in parallel:

See Also