mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
fix(nuxt): speculation rules should be reactive (#9472)
This commit is contained in:
parent
1059b8c9a8
commit
5fe7c1c24d
@ -4,10 +4,10 @@ import { defineNuxtPlugin, useHead } from '#app'
|
|||||||
|
|
||||||
export default defineNuxtPlugin((nuxtApp) => {
|
export default defineNuxtPlugin((nuxtApp) => {
|
||||||
const externalURLs = ref(new Set<string>())
|
const externalURLs = ref(new Set<string>())
|
||||||
useHead({
|
function generateRules () {
|
||||||
script: [
|
return {
|
||||||
() => ({
|
|
||||||
type: 'speculationrules',
|
type: 'speculationrules',
|
||||||
|
key: 'speculationrules',
|
||||||
innerHTML: JSON.stringify({
|
innerHTML: JSON.stringify({
|
||||||
prefetch: [
|
prefetch: [
|
||||||
{
|
{
|
||||||
@ -17,13 +17,18 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
]
|
}
|
||||||
|
const head = useHead({
|
||||||
|
script: [generateRules()]
|
||||||
})
|
})
|
||||||
nuxtApp.hook('link:prefetch', (url) => {
|
nuxtApp.hook('link:prefetch', (url) => {
|
||||||
const { protocol } = parseURL(url)
|
const { protocol } = parseURL(url)
|
||||||
if (protocol && ['http:', 'https:'].includes(protocol)) {
|
if (protocol && ['http:', 'https:'].includes(protocol)) {
|
||||||
externalURLs.value.add(url)
|
externalURLs.value.add(url)
|
||||||
|
head?.patch({
|
||||||
|
script: [generateRules()]
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user