mirror of
https://github.com/nuxt/nuxt.git
synced 2025-03-19 16:01:24 +00:00
fix(nuxt): preserve query/hash when calling navigateTo
with replace (#31244)
This commit is contained in:
parent
3cd43849de
commit
2f833f413b
@ -2,7 +2,7 @@ import { getCurrentInstance, hasInjectionContext, inject, onScopeDispose } from
|
||||
import type { Ref } from 'vue'
|
||||
import type { NavigationFailure, NavigationGuard, RouteLocationNormalized, RouteLocationRaw, Router, useRoute as _useRoute, useRouter as _useRouter } from 'vue-router'
|
||||
import { sanitizeStatusCode } from 'h3'
|
||||
import { hasProtocol, isScriptProtocol, joinURL, withQuery } from 'ufo'
|
||||
import { hasProtocol, isScriptProtocol, joinURL, parseQuery, parseURL, withQuery } from 'ufo'
|
||||
|
||||
import type { PageMeta } from '../../pages/runtime/composables'
|
||||
|
||||
@ -151,7 +151,16 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na
|
||||
// Early redirect on client-side
|
||||
if (import.meta.client && !isExternal && inMiddleware) {
|
||||
if (options?.replace) {
|
||||
return typeof to === 'string' ? { path: to, replace: true } : { ...to, replace: true }
|
||||
if (typeof to === 'string') {
|
||||
const { pathname, search, hash } = parseURL(to)
|
||||
return {
|
||||
path: pathname,
|
||||
...(search && { query: parseQuery(search) }),
|
||||
...(hash && { hash }),
|
||||
replace: true,
|
||||
}
|
||||
}
|
||||
return { ...to, replace: true }
|
||||
}
|
||||
return to
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user