Skip to main content

useRouteError

Accesses the error thrown during an action, loader, or component render to be used in a route module ErrorBoundary.
This hook only works in Data and Framework modes.

Signature

Parameters

None.

Returns

unknown
The error that was thrown during route loading, action execution, or rendering. Can be any value - Error objects, Response objects, or any thrown value.

Usage

Basic error boundary

Handle Response errors

Different error types

Custom error types

JSON error data

Common Patterns

404 Not Found

Authentication errors

Development vs production errors

Logging errors

Retry mechanism

Nested error boundaries

User-friendly error messages

Type Safety

Type guards

Custom error interface

Important Notes

Error propagation

If an ErrorBoundary throws or re-throws an error, it propagates to the parent route’s ErrorBoundary.

Root error boundary

Always define an ErrorBoundary in your root route to catch all unhandled errors.

Render errors vs loader/action errors

The hook catches errors from:
  • Route loader functions
  • Route action functions
  • Component rendering (including child components)