diff --git a/docs/en/guide/custom-theme.md b/docs/en/guide/custom-theme.md index 21cf4e26..57b6e695 100644 --- a/docs/en/guide/custom-theme.md +++ b/docs/en/guide/custom-theme.md @@ -32,6 +32,11 @@ interface Theme { * @required */ Layout: Component + /** + * Content of the not-found page when the site has no `404.md` + * @optional + */ + NotFound?: Component /** * Enhance Vue app instance * @optional @@ -130,9 +135,21 @@ The most basic layout component needs to contain a [``](../reference/ ``` -The above layout simply renders every page's markdown as HTML. The first improvement we can add is to handle 404 errors: +The above layout renders every page's markdown as HTML. That includes the not-found page: when a visitor opens a URL that has no page, `` renders the site's `404.md`, or the theme's `NotFound` component when the site has none. A theme should ship that component, so every site gets a not-found page without writing one. Without it, a small unstyled built-in page is shown instead. + +```js [.vitepress/theme/index.js] +import Layout from './Layout.vue' +import NotFound from './NotFound.vue' + +export default { + Layout, + NotFound +} +``` + +The [`useData()`](../reference/runtime-api#usedata) helper provides us with all the runtime data we need to conditionally render different layouts. For example, `page.isNotFound` is `true` on the not-found page, so the layout can leave out the parts that only make sense for real pages: -```vue{1-4,9-12} +```vue{1-4,9}