fix(nuxt): default statusCode of navigateTo from 301 to 302 (#5173)

Co-authored-by: pooya parsa <pyapar@gmail.com>
This commit is contained in:
Anthony Fu 2022-06-01 05:28:52 +08:00 committed by GitHub
parent 2114a02293
commit fca2ed7cc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -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: 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 * 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('/')` or `navigateTo({ path: '/' })` - redirects to the given path and will set the redirect code to [`302` Found
* `navigateTo('/', { redirectCode: 302 })` - Redirects to the given path and will set the redirect code if the redirect happens on the server side (default: 301) ](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()` - stops the current navigation
* `abortNavigation(error)` - rejects the current navigation with an error * `abortNavigation(error)` - rejects the current navigation with an error

View File

@ -68,7 +68,7 @@ export const navigateTo = (to: RouteLocationRaw, options: NavigateToOptions = {}
const nuxtApp = useNuxtApp() const nuxtApp = useNuxtApp()
if (nuxtApp.ssrContext && nuxtApp.ssrContext.event) { if (nuxtApp.ssrContext && nuxtApp.ssrContext.event) {
const redirectLocation = joinURL(useRuntimeConfig().app.baseURL, router.resolve(to).fullPath || '/') 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 // Client-side redirection using vue-router