Skip to content

Commit 563dc89

Browse files
bonyuta0204brc-dd
andauthored
feat(client): allow disabling link auto-prefetching (#3220)
Co-authored-by: Divyansh Singh <[email protected]>
1 parent 8438e97 commit 563dc89

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

Diff for: src/client/app/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const VitePressApp = defineComponent({
4848
})
4949
})
5050

51-
if (import.meta.env.PROD) {
51+
if (import.meta.env.PROD && site.value.router.prefetchLinks) {
5252
// in prod mode, enable intersectionObserver based pre-fetch
5353
usePrefetch()
5454
}

Diff for: src/node/config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ export async function resolveSiteData(
243243
description: userConfig.description || 'A VitePress site',
244244
base: userConfig.base ? userConfig.base.replace(/([^/])$/, '$1/') : '/',
245245
head: resolveSiteDataHead(userConfig),
246+
router: {
247+
prefetchLinks: userConfig.router?.prefetchLinks ?? true
248+
},
246249
appearance: userConfig.appearance ?? true,
247250
themeConfig: userConfig.themeConfig || {},
248251
locales: userConfig.locales || {},

Diff for: src/node/siteConfig.ts

+5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export interface UserConfig<ThemeConfig = any>
6969

7070
locales?: LocaleConfig<ThemeConfig>
7171

72+
router?: {
73+
prefetchLinks?: boolean
74+
}
75+
7276
appearance?:
7377
| boolean
7478
| 'dark'
@@ -201,6 +205,7 @@ export interface SiteConfig<ThemeConfig = any>
201205
| 'vue'
202206
| 'vite'
203207
| 'shouldPreload'
208+
| 'router'
204209
| 'mpa'
205210
| 'metaChunk'
206211
| 'lastUpdated'

Diff for: types/shared.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ export interface SiteData<ThemeConfig = any> {
126126
locales: LocaleConfig<ThemeConfig>
127127
localeIndex?: string
128128
contentProps?: Record<string, any>
129+
router: {
130+
prefetchLinks: boolean
131+
}
129132
}
130133

131134
export type HeadConfig =

0 commit comments

Comments
 (0)