From 19062c3df07b0e57195eebef48afd039464d1fb8 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Thu, 3 Sep 2026 00:30:15 +0530 Subject: [PATCH] docs: describe the not-found page Adds a routing guide section for `404.md` and per-locale pages, documents `themeConfig.notFound` and `Theme.NotFound`, and updates the custom theme, default theme, i18n, site config and runtime API pages accordingly. Co-Authored-By: Claude Fable 5.1 --- docs/en/guide/custom-theme.md | 42 ++++++++++------- docs/en/guide/extending-default-theme.md | 2 - docs/en/guide/i18n.md | 2 + docs/en/guide/routing.md | 22 +++++++++ docs/en/reference/default-theme-config.md | 56 +++++++++++++++++++++++ docs/en/reference/runtime-api.md | 2 + docs/en/reference/site-config.md | 2 +- 7 files changed, 109 insertions(+), 19 deletions(-) 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}