fix(nuxt): don't add extra baseURL on server useRequestURL (#25765)

This commit is contained in:
Daniel Roe 2024-02-13 10:30:39 +00:00 committed by GitHub
parent f0a7ccd588
commit 29b338f8aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 8 deletions

View File

@ -1,14 +1,10 @@
import { getRequestURL } from 'h3' import { getRequestURL } from 'h3'
import { joinURL } from 'ufo'
import { useRuntimeConfig } from '../nuxt'
import { useRequestEvent } from './ssr' import { useRequestEvent } from './ssr'
/** @since 3.5.0 */ /** @since 3.5.0 */
export function useRequestURL () { export function useRequestURL () {
if (import.meta.server) { if (import.meta.server) {
const url = getRequestURL(useRequestEvent()!) return getRequestURL(useRequestEvent()!)
url.pathname = joinURL(useRuntimeConfig().app.baseURL, url.pathname)
return url
} }
return new URL(window.location.href) return new URL(window.location.href)
} }

View File

@ -593,7 +593,7 @@ describe('nuxt links', () => {
await page.close() await page.close()
}) })
it('expect scroll to top on routes with same component', it('expect scroll to top on routes with same component',
async () => { async () => {
// #22402 // #22402
const page = await createPage('/big-page-1', { const page = await createPage('/big-page-1', {
@ -616,12 +616,12 @@ describe('nuxt links', () => {
await page.waitForFunction(path => window.useNuxtApp?.()._route.fullPath === path, `/big-page-1`) await page.waitForFunction(path => window.useNuxtApp?.()._route.fullPath === path, `/big-page-1`)
expect(await page.evaluate(() => window.scrollY)).toBe(0) expect(await page.evaluate(() => window.scrollY)).toBe(0)
await page.close() await page.close()
}, },
// Flaky behavior when using Webpack // Flaky behavior when using Webpack
{ retry: isWebpack ? 10 : 0 } { retry: isWebpack ? 10 : 0 }
) )
it('expect scroll to top on nested pages', it('expect scroll to top on nested pages',
async () => { async () => {
// #20523 // #20523
const page = await createPage('/nested/foo/test', { const page = await createPage('/nested/foo/test', {
@ -1722,6 +1722,8 @@ describe.skipIf(isDev())('dynamic paths', () => {
(isWebpack && url === '/public.svg') (isWebpack && url === '/public.svg')
).toBeTruthy() ).toBeTruthy()
} }
expect(await $fetch('/foo/url')).toContain('path: /foo/url')
}) })
it('should allow setting relative baseURL', async () => { it('should allow setting relative baseURL', async () => {