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
parent 92b427ce81
commit 43f80f134b
No known key found for this signature in database
GPG Key ID: CBC814C393D93268

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(() => {}),
])
}