mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): respect query/hash for external routes in navigateTo
(#21500)
This commit is contained in:
parent
03186d6d44
commit
05a8c2d955
@ -2,7 +2,7 @@ import { getCurrentInstance, hasInjectionContext, inject, onUnmounted } from 'vu
|
|||||||
import type { Ref } from 'vue'
|
import type { Ref } from 'vue'
|
||||||
import type { NavigationFailure, NavigationGuard, RouteLocationNormalized, RouteLocationPathRaw, RouteLocationRaw, Router, useRoute as _useRoute, useRouter as _useRouter } from '#vue-router'
|
import type { NavigationFailure, NavigationGuard, RouteLocationNormalized, RouteLocationPathRaw, RouteLocationRaw, Router, useRoute as _useRoute, useRouter as _useRouter } from '#vue-router'
|
||||||
import { sanitizeStatusCode } from 'h3'
|
import { sanitizeStatusCode } from 'h3'
|
||||||
import { hasProtocol, joinURL, parseURL } from 'ufo'
|
import { hasProtocol, joinURL, parseURL, withQuery } from 'ufo'
|
||||||
|
|
||||||
import { useNuxtApp, useRuntimeConfig } from '../nuxt'
|
import { useNuxtApp, useRuntimeConfig } from '../nuxt'
|
||||||
import type { NuxtError } from './error'
|
import type { NuxtError } from './error'
|
||||||
@ -113,7 +113,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na
|
|||||||
to = '/'
|
to = '/'
|
||||||
}
|
}
|
||||||
|
|
||||||
const toPath = typeof to === 'string' ? to : ((to as RouteLocationPathRaw).path || '/')
|
const toPath = typeof to === 'string' ? to : (withQuery((to as RouteLocationPathRaw).path || '/', to.query || {}) + (to.hash || ''))
|
||||||
|
|
||||||
// Early open handler
|
// Early open handler
|
||||||
if (options?.open) {
|
if (options?.open) {
|
||||||
|
@ -788,7 +788,7 @@ describe('navigate external', () => {
|
|||||||
it('should redirect to example.com', async () => {
|
it('should redirect to example.com', async () => {
|
||||||
const { headers } = await fetch('/navigate-to-external/', { redirect: 'manual' })
|
const { headers } = await fetch('/navigate-to-external/', { redirect: 'manual' })
|
||||||
|
|
||||||
expect(headers.get('location')).toEqual('https://example.com/')
|
expect(headers.get('location')).toEqual('https://example.com/?redirect=false#test')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should redirect to api endpoint', async () => {
|
it('should redirect to api endpoint', async () => {
|
||||||
|
@ -25,7 +25,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM
|
|||||||
|
|
||||||
it('default client bundle size', async () => {
|
it('default client bundle size', async () => {
|
||||||
stats.client = await analyzeSizes('**/*.js', publicDir)
|
stats.client = await analyzeSizes('**/*.js', publicDir)
|
||||||
expect(roundToKilobytes(stats.client.totalBytes)).toMatchInlineSnapshot('"97.1k"')
|
expect(roundToKilobytes(stats.client.totalBytes)).toMatchInlineSnapshot('"97.2k"')
|
||||||
expect(stats.client.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(`
|
expect(stats.client.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(`
|
||||||
[
|
[
|
||||||
"_nuxt/entry.js",
|
"_nuxt/entry.js",
|
||||||
|
@ -8,5 +8,5 @@ if (useRoute().path === '/navigate-to-external') {
|
|||||||
throw new Error('this should not run')
|
throw new Error('this should not run')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
await navigateTo('https://example.com/', { external: true, replace: true })
|
await navigateTo({ path: 'https://example.com/', query: { redirect: false }, hash: '#test' }, { external: true, replace: true })
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user