mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-19 01:45:53 +00:00
fix(nuxt): sync setResponseStatus
signature with h3 (#19987)
This commit is contained in:
parent
575f950cfc
commit
822202239c
@ -10,11 +10,13 @@ Nuxt provides composables and utilities for first-class server-side-rendering su
|
||||
`setResponseStatus` can only be called within component setup functions, plugins, and route middleware.
|
||||
|
||||
```js
|
||||
const event = useRequestEvent()
|
||||
|
||||
// Set the status code to 404 for a custom 404 page
|
||||
setResponseStatus(404)
|
||||
setResponseStatus(event, 404)
|
||||
|
||||
// Set the status message as well
|
||||
setResponseStatus(404, 'Page Not Found')
|
||||
setResponseStatus(event, 404, 'Page Not Found')
|
||||
```
|
||||
|
||||
::alert{icon=👉}
|
||||
|
@ -111,7 +111,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na
|
||||
// Let vue-router handle internal redirects within middleware
|
||||
// to prevent the navigation happening after response is sent
|
||||
if (isProcessingMiddleware() && !isExternal) {
|
||||
setResponseStatus(options?.redirectCode || 302)
|
||||
setResponseStatus(nuxtApp.ssrContext.event, options?.redirectCode || 302)
|
||||
return to
|
||||
}
|
||||
const redirectLocation = isExternal ? toPath : joinURL(useRuntimeConfig().app.baseURL, router.resolve(to).fullPath || '/')
|
||||
|
@ -25,7 +25,13 @@ export function useRequestFetch (): typeof global.$fetch {
|
||||
return event?.$fetch as typeof globalThis.$fetch || globalThis.$fetch
|
||||
}
|
||||
|
||||
export function setResponseStatus (code: number, message?: string) {
|
||||
export function setResponseStatus (event: H3Event, code?: number, message?: string): void
|
||||
/** @deprecated Pass `event` as first option. */
|
||||
export function setResponseStatus (code: number, message?: string): void
|
||||
export function setResponseStatus (arg1: H3Event | number | undefined, arg2?: number | string, arg3?: string) {
|
||||
if (process.client) { return }
|
||||
_setResponseStatus(useRequestEvent(), code, message)
|
||||
if (arg1 && typeof arg1 !== 'number') {
|
||||
return _setResponseStatus(arg1, arg2 as number | undefined, arg3)
|
||||
}
|
||||
return _setResponseStatus(useRequestEvent(), arg1, arg2 as string | undefined)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user