mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 09:02:03 +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) {
|
if (!options?.external) {
|
||||||
throw new Error('Navigating to an external URL is not allowed by default. Use `navigateTo(url, { external: true })`.')
|
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)) {
|
if (protocol && isScriptProtocol(protocol)) {
|
||||||
throw new Error(`Cannot navigate to a URL with '${protocol}' protocol.`)
|
throw new Error(`Cannot navigate to a URL with '${protocol}' protocol.`)
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { parseURL } from 'ufo'
|
|
||||||
import { useHead } from '@unhead/vue'
|
import { useHead } from '@unhead/vue'
|
||||||
import { defineNuxtPlugin } from '../nuxt'
|
import { defineNuxtPlugin } from '../nuxt'
|
||||||
|
|
||||||
|
const SUPPORTED_PROTOCOLS = ['http:', 'https:']
|
||||||
|
|
||||||
export default defineNuxtPlugin({
|
export default defineNuxtPlugin({
|
||||||
name: 'nuxt:cross-origin-prefetch',
|
name: 'nuxt:cross-origin-prefetch',
|
||||||
setup (nuxtApp) {
|
setup (nuxtApp) {
|
||||||
@ -26,8 +27,7 @@ export default defineNuxtPlugin({
|
|||||||
script: [generateRules()],
|
script: [generateRules()],
|
||||||
})
|
})
|
||||||
nuxtApp.hook('link:prefetch', (url) => {
|
nuxtApp.hook('link:prefetch', (url) => {
|
||||||
const { protocol } = parseURL(url)
|
if (SUPPORTED_PROTOCOLS.some(p => url.startsWith(p)) && SUPPORTED_PROTOCOLS.includes(new URL(url).protocol)) {
|
||||||
if (protocol && ['http:', 'https:'].includes(protocol)) {
|
|
||||||
externalURLs.value.add(url)
|
externalURLs.value.add(url)
|
||||||
head?.patch({
|
head?.patch({
|
||||||
script: [generateRules()],
|
script: [generateRules()],
|
||||||
|
Loading…
Reference in New Issue
Block a user