Summary
A redirectResponse 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
The URL to redirect to. Can be a relative path (e.g.,
/login) or absolute URL.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 redirect302- Temporary redirect (default)303- See Other (common after POST)307- Temporary redirect (preserves method)308- Permanent redirect (preserves method)
Returns
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:Related Functions
redirectDocument- Force a full document reloadreplace- Redirect using history.replaceStatedata- Return data with custom headers/status
Notes
- Redirects are typically thrown rather than returned for better type inference
- The
redirectresponse 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