Skip to content

Commit

Permalink
fix(nuxt): prefetch object-syntax routes with <NuxtLink> (#19144)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mini-ghost committed Feb 20, 2023
1 parent 29d6094 commit 268cded
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/nuxt/src/app/components/nuxt-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
const el = process.server ? undefined : ref<HTMLElement | null>(null)
if (process.client) {
checkPropConflicts(props, 'prefetch', 'noPrefetch')
const shouldPrefetch = props.prefetch !== false && props.noPrefetch !== true && typeof to.value === 'string' && props.target !== '_blank' && !isSlowConnection()
const shouldPrefetch = props.prefetch !== false && props.noPrefetch !== true && props.target !== '_blank' && !isSlowConnection()
if (shouldPrefetch) {
const nuxtApp = useNuxtApp()
let idleId: number
Expand All @@ -189,8 +189,10 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
unobserve = observer!.observe(el.value, async () => {
unobserve?.()
unobserve = null

const path = typeof to.value === 'string' ? to.value : router.resolve(to.value).fullPath
await Promise.all([
nuxtApp.hooks.callHook('link:prefetch', to.value as string).catch(() => {}),
nuxtApp.hooks.callHook('link:prefetch', path).catch(() => {}),
!isExternal.value && preloadRouteComponents(to.value as string, router).catch(() => {})
])
prefetched.value = true
Expand Down

0 comments on commit 268cded

Please sign in to comment.