fix(nuxt): pass absolute external link urls to link:prefetch (#29321)

This commit is contained in:
Daniel Roe 2024-10-08 15:28:54 +02:00 committed by GitHub
parent 0b4ac63480
commit b9f2ce0f42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -328,8 +328,9 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
const path = typeof to.value === 'string'
? to.value
: isExternal.value ? resolveRouteObject(to.value) : router.resolve(to.value).fullPath
const normalizedPath = isExternal.value ? new URL(path, window.location.href).href : path
await Promise.all([
nuxtApp.hooks.callHook('link:prefetch', path).catch(() => {}),
nuxtApp.hooks.callHook('link:prefetch', normalizedPath).catch(() => {}),
!isExternal.value && !hasTarget.value && preloadRouteComponents(to.value as string, router).catch(() => {}),
])
}