From fca2ed7cc5ca57725ba3ca934f175323e5b9d1fd Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Wed, 1 Jun 2022 05:28:52 +0800 Subject: [PATCH] fix(nuxt): default statusCode of `navigateTo` from `301` to `302` (#5173) Co-authored-by: pooya parsa --- docs/content/2.guide/3.directory-structure/7.middleware.md | 6 ++++-- packages/nuxt/src/app/composables/router.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/content/2.guide/3.directory-structure/7.middleware.md b/docs/content/2.guide/3.directory-structure/7.middleware.md index e09e336f7a..25bb8a2347 100644 --- a/docs/content/2.guide/3.directory-structure/7.middleware.md +++ b/docs/content/2.guide/3.directory-structure/7.middleware.md @@ -41,8 +41,10 @@ Nuxt provides two globally available helpers that can be returned directly from Unlike navigation guards in [the vue-router docs](https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards), a third `next()` argument is not passed, and redirects or route cancellation is handled by returning a value from the middleware. Possible return values are: * nothing - does not block navigation and will move to the next middleware function, if any, or complete the route navigation -* `navigateTo('/')` or `navigateTo({ path: '/' })` - redirects to the given path -* `navigateTo('/', { redirectCode: 302 })` - Redirects to the given path and will set the redirect code if the redirect happens on the server side (default: 301) +* `navigateTo('/')` or `navigateTo({ path: '/' })` - redirects to the given path and will set the redirect code to [`302` Found +](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302) if the redirect happens on the server side +* `navigateTo('/', { redirectCode: 301 })` - redirects to the given path and will set the redirect code to [`301` Moved Permanently +](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/301) if the redirect happens on the server side * `abortNavigation()` - stops the current navigation * `abortNavigation(error)` - rejects the current navigation with an error diff --git a/packages/nuxt/src/app/composables/router.ts b/packages/nuxt/src/app/composables/router.ts index 2373f61a72..55530d32ac 100644 --- a/packages/nuxt/src/app/composables/router.ts +++ b/packages/nuxt/src/app/composables/router.ts @@ -68,7 +68,7 @@ export const navigateTo = (to: RouteLocationRaw, options: NavigateToOptions = {} const nuxtApp = useNuxtApp() if (nuxtApp.ssrContext && nuxtApp.ssrContext.event) { const redirectLocation = joinURL(useRuntimeConfig().app.baseURL, router.resolve(to).fullPath || '/') - return nuxtApp.callHook('app:redirected').then(() => sendRedirect(nuxtApp.ssrContext.event, redirectLocation, options.redirectCode || 301)) + return nuxtApp.callHook('app:redirected').then(() => sendRedirect(nuxtApp.ssrContext.event, redirectLocation, options.redirectCode || 302)) } } // Client-side redirection using vue-router