Skip to main content
Glama
error-handling.md2.25 kB
--- title: Error handling description: Learn how to handle unmatched routes and errors in your app when using Expo Router. --- This guide specifies how to handle unmatched routes and errors in your app when using Expo Router. ## Unmatched routes Native apps don't have a server so there are technically no 404s. However, if you're implementing a router universally, then it makes sense to handle missing routes. This is done automatically for each app, but you can also customize it. ```tsx app/+not-found.tsx ``` This will render the default `Unmatched`. You can export any component you want to render instead. We recommend having a link to `/` so users can navigate back to the home screen. ### Route priority On web, files are served in the following order: 1. Static files in the **public** directory. 2. Standard and dynamic routes in the app directory. 3. [API routes](/router/reference/api-routes) in the app directory. 4. Not-found routes will be served last with a 404 status code. ## Error handling Expo Router enables fine-tuned error handling to enable a more opinionated data-loading strategy in the future. You can export a nested [`ErrorBoundary`](/versions/latest/sdk/router/#errorboundary) component from any route to intercept and format component-level errors using [React Error Boundaries](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary): {/* prettier-ignore */} ```tsx app/home.tsx /* @info */ /* @end */ return ( <Text>{error.message}</Text> <Text onPress={retry}>Try Again?</Text> ); } ``` When you export an `ErrorBoundary` the route will be wrapped with a React Error Boundary effectively: ```tsx Virtual function Route({ ErrorBoundary, Component }) { return ( ); } ``` When `ErrorBoundary` is not present, the error will be thrown to the nearest parent's `ErrorBoundary` and accepts [`error`](/versions/latest/sdk/router/#error) and [`retry`](/versions/latest/sdk/router/#retry) props. ### Work in progress React Native LogBox needs to be presented less aggressively to develop with errors. Currently, it shows for `console.error` and `console.warn`. However, it should ideally only show for uncaught errors.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jaksm/expo-docs-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server