diff --git a/docs/content/2.guide/3.directory-structure/10.pages.md b/docs/content/2.guide/3.directory-structure/10.pages.md index 595059f9d5..d1eeea8a0f 100644 --- a/docs/content/2.guide/3.directory-structure/10.pages.md +++ b/docs/content/2.guide/3.directory-structure/10.pages.md @@ -146,6 +146,10 @@ Navigating to `/hello/world` would render:

["hello", "world"]

``` +::alert{type="info"} +Nuxt also supports a custom `pages/404.vue` file which will handle all routes that are not otherwise matched (and set a 404 error code). +:: + ## Nested Routes It is possible to display [nested routes](https://next.router.vuejs.org/guide/essentials/nested-routes.html) with ``. diff --git a/packages/nuxt/src/pages/runtime/router.ts b/packages/nuxt/src/pages/runtime/router.ts index 79fcbf15ed..9b3e6d6854 100644 --- a/packages/nuxt/src/pages/runtime/router.ts +++ b/packages/nuxt/src/pages/runtime/router.ts @@ -161,6 +161,8 @@ export default defineNuxtPlugin((nuxtApp) => { statusCode: 404, statusMessage: `Page not found: ${to.fullPath}` })]) + } else if (process.server && to.matched[0].name === '404' && nuxtApp.ssrContext) { + nuxtApp.ssrContext.res.statusCode = 404 } })