Skip to main content

Summary

A redirect Response that sets the status code and the Location header. Defaults to 302 Found. Use redirect to navigate users to a different URL from loaders or actions.

Signature

Parameters

string
required
The URL to redirect to. Can be a relative path (e.g., /login) or absolute URL.
number | ResponseInit
Either a status code number or a ResponseInit object with status and headers.Defaults to 302 if not specified.Common redirect status codes:
  • 301 - Permanent redirect
  • 302 - Temporary redirect (default)
  • 303 - See Other (common after POST)
  • 307 - Temporary redirect (preserves method)
  • 308 - Permanent redirect (preserves method)

Returns

Response
A Response object with the redirect status code and Location header set.

Examples

Basic redirect

Redirect with custom status code

Redirect with headers

Permanent redirect

Common Use Cases

Authentication guards

Redirect unauthenticated users to login:

Post-action navigation

Redirect after successful form submission:

Conditional routing

Redirect based on user role or permissions:
  • redirectDocument - Force a full document reload
  • replace - Redirect using history.replaceState
  • data - Return data with custom headers/status

Notes

  • Redirects are typically thrown rather than returned for better type inference
  • The redirect response will trigger client-side navigation in React Router
  • Use appropriate status codes for SEO and browser caching behavior
  • For external URLs, the browser will perform a full page navigation