2022-10-06 09:15:30 +00:00
|
|
|
---
|
|
|
|
description: setResponseStatus sets the statusCode (and optionally the statusMessage) of the response.
|
|
|
|
---
|
2022-08-02 16:01:59 +00:00
|
|
|
# `setResponseStatus`
|
|
|
|
|
|
|
|
Nuxt provides composables and utilities for first-class server-side-rendering support.
|
|
|
|
|
2022-10-06 09:15:30 +00:00
|
|
|
`setResponseStatus` sets the statusCode (and optionally the statusMessage) of the response.
|
2022-08-02 16:01:59 +00:00
|
|
|
|
|
|
|
`setResponseStatus` can only be called within component setup functions, plugins, and route middleware.
|
|
|
|
|
|
|
|
```js
|
|
|
|
// Set the status code to 404 for a custom 404 page
|
|
|
|
setResponseStatus(404)
|
|
|
|
|
|
|
|
// Set the status message as well
|
|
|
|
setResponseStatus(404, 'Page Not Found')
|
|
|
|
```
|
|
|
|
|
|
|
|
::alert{icon=👉}
|
|
|
|
In the browser, `setResponseStatus` will have no effect.
|
|
|
|
::
|