ErrorLayout
This component is mainly used in conjunction with wrap/eject in Custom Theme , and is different from components that are directly imported in MDX. You can modify the styles and functions by passing component props or directly overriding the component. If you override the entire component through eject, please note that the reading of the corresponding configuration options of the component will become invalid and you need to control it yourself.
ErrorLayout is the error page displayed when page data or code fails to load, or when a page fails to render. Rspress renders it automatically, with actions to reload the page or return to the homepage.
In development, the default component also displays error details. These details are hidden in production.
Unmatched routes use NotFoundLayout to display a 404 page.
Usage
Override ErrorLayout through a custom theme:
To reuse the default error page, import ErrorLayout from @rspress/core/theme-original and forward all props to it.
Page context may be unavailable when an error occurs. Use the lang and homeHref props instead of hooks that depend on page data, such as usePage(), useLang(), or useVersion().
Props
Rspress passes the following props to ErrorLayout:
error
- Type:
unknown - Required: Yes
The error caught while loading or rendering the page. Narrow its type before accessing properties such as message or stack.
lang
- Type:
string - Required: Yes
The current language code, resolved from the URL and site configuration. Use it to render localized error messages.
homeHref
- Type:
string - Required: Yes
The homepage URL, including the site's base path and the current language and version prefixes when applicable. Use this value for the home link instead of hardcoding /.