diff --git a/packages/nuxt/src/app/components/nuxt-link.ts b/packages/nuxt/src/app/components/nuxt-link.ts index 6efcab60b3..16116ebcfd 100644 --- a/packages/nuxt/src/app/components/nuxt-link.ts +++ b/packages/nuxt/src/app/components/nuxt-link.ts @@ -8,7 +8,7 @@ import type { } from 'vue' import { computed, defineComponent, h, inject, onBeforeUnmount, onMounted, provide, ref, resolveComponent } from 'vue' import type { RouteLocation, RouteLocationRaw, Router, RouterLink, RouterLinkProps, useLink } from '#vue-router' -import { hasProtocol, joinURL, parseQuery, parseURL, withTrailingSlash, withoutTrailingSlash } from 'ufo' +import { hasProtocol, joinURL, parseQuery, withTrailingSlash, withoutTrailingSlash } from 'ufo' import { preloadRouteComponents } from '../composables/preload' import { onNuxtReady } from '../composables/ready' import { navigateTo, useRouter } from '../composables/router' @@ -392,7 +392,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) { get route () { if (!href.value) { return undefined } - const url = parseURL(href.value) + const url = new URL(href.value, import.meta.client ? window.location.href : 'http://localhost') return { path: url.pathname, fullPath: url.pathname, diff --git a/packages/nuxt/src/app/components/test-component-wrapper.ts b/packages/nuxt/src/app/components/test-component-wrapper.ts index 1581e09364..8b0da24381 100644 --- a/packages/nuxt/src/app/components/test-component-wrapper.ts +++ b/packages/nuxt/src/app/components/test-component-wrapper.ts @@ -1,4 +1,3 @@ -import { parseURL } from 'ufo' import { defineComponent, h } from 'vue' import { parseQuery } from 'vue-router' import { resolve } from 'pathe' @@ -10,7 +9,7 @@ export default (url: string) => defineComponent({ name: 'NuxtTestComponentWrapper', async setup (props, { attrs }) { - const query = parseQuery(parseURL(url).search) + const query = parseQuery(new URL(url, 'http://localhost').search) const urlProps = query.props ? destr>(query.props as string) : {} const path = resolve(query.path as string) if (!path.startsWith(devRootDir)) { diff --git a/packages/nuxt/src/app/plugins/payload.client.ts b/packages/nuxt/src/app/plugins/payload.client.ts index c50b3bd45a..3dc431e63d 100644 --- a/packages/nuxt/src/app/plugins/payload.client.ts +++ b/packages/nuxt/src/app/plugins/payload.client.ts @@ -1,4 +1,3 @@ -import { parseURL } from 'ufo' import { defineNuxtPlugin } from '../nuxt' import { loadPayload } from '../composables/payload' import { onNuxtReady } from '../composables/ready' @@ -24,7 +23,8 @@ export default defineNuxtPlugin({ onNuxtReady(() => { // Load payload into cache nuxtApp.hooks.hook('link:prefetch', async (url) => { - if (!parseURL(url).protocol) { + const { protocol } = new URL(url, window.location.href) + if (!protocol) { await loadPayload(url) } }) diff --git a/packages/nuxt/src/app/plugins/router.ts b/packages/nuxt/src/app/plugins/router.ts index 38c93085d4..8fc32754b2 100644 --- a/packages/nuxt/src/app/plugins/router.ts +++ b/packages/nuxt/src/app/plugins/router.ts @@ -1,6 +1,6 @@ import type { Ref } from 'vue' import { computed, defineComponent, h, isReadonly, reactive } from 'vue' -import { isEqual, joinURL, parseQuery, parseURL, stringifyParsedURL, stringifyQuery, withoutBase } from 'ufo' +import { isEqual, joinURL, parseQuery, stringifyParsedURL, stringifyQuery, withoutBase } from 'ufo' import { createError } from 'h3' import { defineNuxtPlugin, useRuntimeConfig } from '../nuxt' import { getRouteRules } from '../composables/manifest' @@ -45,7 +45,7 @@ function getRouteFromPath (fullPath: string | Partial) { }) } - const url = parseURL(fullPath.toString()) + const url = new URL(fullPath.toString(), import.meta.client ? window.location.href : 'http://localhost') return { path: url.pathname, fullPath,