mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): use URL
constructor to resolve external protocols
This commit is contained in:
parent
8e793ad5cc
commit
5f0693a69a
@ -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.`)
|
||||
}
|
||||
|
@ -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()],
|
||||
|
Loading…
Reference in New Issue
Block a user