Skip to content

Commit ea22d3f

Browse files
committed
fix(nuxt): use URL for parsing URLs rather than parseURL
1 parent 5f0693a commit ea22d3f

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

packages/nuxt/src/app/components/nuxt-link.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
} from 'vue'
99
import { computed, defineComponent, h, inject, onBeforeUnmount, onMounted, provide, ref, resolveComponent } from 'vue'
1010
import type { RouteLocation, RouteLocationRaw, Router, RouterLink, RouterLinkProps, useLink } from '#vue-router'
11-
import { hasProtocol, joinURL, parseQuery, parseURL, withTrailingSlash, withoutTrailingSlash } from 'ufo'
11+
import { hasProtocol, joinURL, parseQuery, withTrailingSlash, withoutTrailingSlash } from 'ufo'
1212
import { preloadRouteComponents } from '../composables/preload'
1313
import { onNuxtReady } from '../composables/ready'
1414
import { navigateTo, useRouter } from '../composables/router'
@@ -392,7 +392,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
392392
get route () {
393393
if (!href.value) { return undefined }
394394

395-
const url = parseURL(href.value)
395+
const url = new URL(href.value, import.meta.client ? window.location.href : 'http://localhost')
396396
return {
397397
path: url.pathname,
398398
fullPath: url.pathname,

packages/nuxt/src/app/components/test-component-wrapper.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { parseURL } from 'ufo'
21
import { defineComponent, h } from 'vue'
32
import { parseQuery } from 'vue-router'
43
import { resolve } from 'pathe'
@@ -10,7 +9,7 @@ export default (url: string) => defineComponent({
109
name: 'NuxtTestComponentWrapper',
1110

1211
async setup (props, { attrs }) {
13-
const query = parseQuery(parseURL(url).search)
12+
const query = parseQuery(new URL(url, 'http://localhost').search)
1413
const urlProps = query.props ? destr<Record<string, any>>(query.props as string) : {}
1514
const path = resolve(query.path as string)
1615
if (!path.startsWith(devRootDir)) {

packages/nuxt/src/app/plugins/payload.client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { parseURL } from 'ufo'
21
import { defineNuxtPlugin } from '../nuxt'
32
import { loadPayload } from '../composables/payload'
43
import { onNuxtReady } from '../composables/ready'
@@ -24,7 +23,8 @@ export default defineNuxtPlugin({
2423
onNuxtReady(() => {
2524
// Load payload into cache
2625
nuxtApp.hooks.hook('link:prefetch', async (url) => {
27-
if (!parseURL(url).protocol) {
26+
const { protocol } = new URL(url, window.location.href)
27+
if (!protocol) {
2828
await loadPayload(url)
2929
}
3030
})

packages/nuxt/src/app/plugins/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Ref } from 'vue'
22
import { computed, defineComponent, h, isReadonly, reactive } from 'vue'
3-
import { isEqual, joinURL, parseQuery, parseURL, stringifyParsedURL, stringifyQuery, withoutBase } from 'ufo'
3+
import { isEqual, joinURL, parseQuery, stringifyParsedURL, stringifyQuery, withoutBase } from 'ufo'
44
import { createError } from 'h3'
55
import { defineNuxtPlugin, useRuntimeConfig } from '../nuxt'
66
import { getRouteRules } from '../composables/manifest'
@@ -45,7 +45,7 @@ function getRouteFromPath (fullPath: string | Partial<Route>) {
4545
})
4646
}
4747

48-
const url = parseURL(fullPath.toString())
48+
const url = new URL(fullPath.toString(), import.meta.client ? window.location.href : 'http://localhost')
4949
return {
5050
path: url.pathname,
5151
fullPath,

0 commit comments

Comments
 (0)