From 28a2d192f6d3280321e314f2ce957ca85ca13321 Mon Sep 17 00:00:00 2001 From: EGOIST <0x142857@gmail.com> Date: Mon, 8 Apr 2019 17:12:14 +0800 Subject: [PATCH] fix: allow to turn off prefetching globally --- README.md | 8 ++++++++ src/index.js | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 983d791..7e10333 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,14 @@ new VueRouter({ }) ``` +It's also possible to turn of prefetching globally: + +```js +Vue.use(RouterPrefetch, { + prefetch: false +}) +``` + ### prefetchFiles - Type: `string[]` diff --git a/src/index.js b/src/index.js index 580a10f..629a9a1 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,10 @@ import prefetch from './prefetch' import { canPrefetch, supportIntersectionObserver, inBrowser } from './utils' -function installRouterPrefetch(Vue, { componentName = 'RouterLink' } = {}) { +function installRouterPrefetch( + Vue, + { componentName = 'RouterLink', prefetch: enablePrefetch = true } = {} +) { const observer = supportIntersectionObserver && new window.IntersectionObserver(entries => { @@ -40,7 +43,7 @@ function installRouterPrefetch(Vue, { componentName = 'RouterLink' } = {}) { props: { prefetch: { type: Boolean, - default: true + default: enablePrefetch }, prefetchFiles: { type: Array