fix(nuxt): return 404 if hitting 404.vue (#4460)

* fix(nuxt): return 404 if hitting `404.vue`

* docs: add info about `pages/404.vue`
This commit is contained in:
Daniel Roe 2022-04-20 15:24:08 +01:00 committed by GitHub
parent 98586bcf25
commit d0ae5851e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -146,6 +146,10 @@ Navigating to `/hello/world` would render:
<p>["hello", "world"]</p> <p>["hello", "world"]</p>
``` ```
::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 ## Nested Routes
It is possible to display [nested routes](https://next.router.vuejs.org/guide/essentials/nested-routes.html) with `<NuxtPage>`. It is possible to display [nested routes](https://next.router.vuejs.org/guide/essentials/nested-routes.html) with `<NuxtPage>`.

View File

@ -161,6 +161,8 @@ export default defineNuxtPlugin((nuxtApp) => {
statusCode: 404, statusCode: 404,
statusMessage: `Page not found: ${to.fullPath}` statusMessage: `Page not found: ${to.fullPath}`
})]) })])
} else if (process.server && to.matched[0].name === '404' && nuxtApp.ssrContext) {
nuxtApp.ssrContext.res.statusCode = 404
} }
}) })