diff --git a/packages/nuxt/src/app/composables/router.ts b/packages/nuxt/src/app/composables/router.ts index 072ff76155..85d9670266 100644 --- a/packages/nuxt/src/app/composables/router.ts +++ b/packages/nuxt/src/app/composables/router.ts @@ -140,7 +140,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na if (!options?.external) { throw new Error('Navigating to an external URL is not allowed by default. Use `navigateTo(url, { external: true })`.') } - const protocol = parseURL(toPath).protocol + const { protocol } = new URL(toPath) if (protocol && isScriptProtocol(protocol)) { throw new Error(`Cannot navigate to a URL with '${protocol}' protocol.`) } diff --git a/packages/nuxt/src/app/plugins/cross-origin-prefetch.client.ts b/packages/nuxt/src/app/plugins/cross-origin-prefetch.client.ts index 3ae277ab47..66788be26b 100644 --- a/packages/nuxt/src/app/plugins/cross-origin-prefetch.client.ts +++ b/packages/nuxt/src/app/plugins/cross-origin-prefetch.client.ts @@ -1,8 +1,9 @@ import { ref } from 'vue' -import { parseURL } from 'ufo' import { useHead } from '@unhead/vue' import { defineNuxtPlugin } from '../nuxt' +const SUPPORTED_PROTOCOLS = ['http:', 'https:'] + export default defineNuxtPlugin({ name: 'nuxt:cross-origin-prefetch', setup (nuxtApp) { @@ -26,8 +27,7 @@ export default defineNuxtPlugin({ script: [generateRules()], }) nuxtApp.hook('link:prefetch', (url) => { - const { protocol } = parseURL(url) - if (protocol && ['http:', 'https:'].includes(protocol)) { + if (SUPPORTED_PROTOCOLS.some(p => url.startsWith(p)) && SUPPORTED_PROTOCOLS.includes(new URL(url).protocol)) { externalURLs.value.add(url) head?.patch({ script: [generateRules()],