---
id: error-boundaries
track: learn
product: router
locale: en
order: 7
revision: 2
sourceCheckedOn: "2026-08-03"
versionRange: "Start ^1 / Router ^1"
verifiedAgainst: "@tanstack/react-start@1.168.34 + @tanstack/react-router@1.170.18"
contentModel: 2
prerequisites:
  - "Route tree and loader basics"
sourceRefs:
  - "https://tanstack.com/start/latest/docs/framework/react/guide/error-boundaries"
---

# Contain errors in the right route

> Use a global default as the safety net and route errorComponent to isolate local data or render failures.

**Outcome:** Provide recoverable UI for loader and render errors without leaking internals.

## Errors bubble through the route tree

Errors from a loader or route component go to the nearest errorComponent. Production apps should set defaultErrorComponent on the Router and override it where a page needs independent recovery.

## Offer recovery, not a stack trace

reset clears the error boundary. User-facing UI should use stable copy; send detailed errors to controlled logging instead of rendering a message that may contain internals.

File: `src/routes/issues/index.tsx`

```tsx
import type { ErrorComponentProps } from '@tanstack/react-router'

export const Route = createFileRoute('/issues/')({
  loader: loadIssues,
  errorComponent: IssuesError,
  component: IssuesPage,
})

function IssuesError({ reset }: ErrorComponentProps) {
  return (
    <section role="alert">
      <h1>Issues could not be loaded.</h1>
      <button onClick={reset}>Try again</button>
    </section>
  )
}
```

## Practice and verification

### Completion checkpoint

Loader and render errors reach the nearest route errorComponent while sibling routes remain navigable.

### Exercise

Throw notFound for a missing issue and route network failures to a retryable errorComponent.

### Verification

Trigger 404 and 500 paths separately; messaging and recovery should differ while navigation remains usable.

### Common pitfalls

- Rendering not-found, redirects, and unknown failures as one error.
- Retrying in an errorComponent without resetting route state.

## Official sources

- https://tanstack.com/start/latest/docs/framework/react/guide/error-boundaries
