mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 01:53:55 +00:00
fix(nuxt): prefetch object-syntax routes with <NuxtLink>
(#19144)
This commit is contained in:
parent
29d6094a8d
commit
268cded26c
@ -176,7 +176,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
|||||||
const el = process.server ? undefined : ref<HTMLElement | null>(null)
|
const el = process.server ? undefined : ref<HTMLElement | null>(null)
|
||||||
if (process.client) {
|
if (process.client) {
|
||||||
checkPropConflicts(props, 'prefetch', 'noPrefetch')
|
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) {
|
if (shouldPrefetch) {
|
||||||
const nuxtApp = useNuxtApp()
|
const nuxtApp = useNuxtApp()
|
||||||
let idleId: number
|
let idleId: number
|
||||||
@ -189,8 +189,10 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
|||||||
unobserve = observer!.observe(el.value, async () => {
|
unobserve = observer!.observe(el.value, async () => {
|
||||||
unobserve?.()
|
unobserve?.()
|
||||||
unobserve = null
|
unobserve = null
|
||||||
|
|
||||||
|
const path = typeof to.value === 'string' ? to.value : router.resolve(to.value).fullPath
|
||||||
await Promise.all([
|
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(() => {})
|
!isExternal.value && preloadRouteComponents(to.value as string, router).catch(() => {})
|
||||||
])
|
])
|
||||||
prefetched.value = true
|
prefetched.value = true
|
||||||
|
Loading…
Reference in New Issue
Block a user