You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-8
Original file line number
Diff line number
Diff line change
@@ -16,17 +16,21 @@
16
16
yarn add vue-router-prefetch
17
17
```
18
18
19
+
If you're using Vue 2, you should install `vue-router-prefetch@1` instead.
20
+
19
21
## Usage
20
22
21
23
You need to use this plugin after `vue-router`:
22
24
23
25
```js
24
-
importVuefrom'vue'
25
-
importRouterfrom'vue-router'
26
+
import{ createApp }from'vue'
27
+
import{ createRouter }from'vue-router'
26
28
importRouterPrefetchfrom'vue-router-prefetch'
27
29
28
-
Vue.use(Router)
29
-
Vue.use(RouterPrefetch)
30
+
constapp=createApp()
31
+
constrouter=createRouter()
32
+
app.use(router)
33
+
app.use(RouterPrefetch)
30
34
```
31
35
32
36
Then you can use `<router-link>` without any changes, when this component is visible in viewport, it will automatically prefetch the (async) route component.
@@ -36,7 +40,7 @@ Then you can use `<router-link>` without any changes, when this component is vis
36
40
You can also register it as a new component instead of overriding `<router-link>`:
37
41
38
42
```js
39
-
Vue.use(RouterPrefetch, {
43
+
app.use(RouterPrefetch, {
40
44
componentName:'QuickLink'
41
45
})
42
46
```
@@ -62,7 +66,7 @@ Whether to prefetch the matched route component.
62
66
You can also set `meta.prefetch` on vue-router's `route` object to disable prefetching this route for all `<router-link>`s:
63
67
64
68
```js
65
-
newVueRouter({
69
+
createRouter({
66
70
routes: [
67
71
{
68
72
path:'/some-async-page',
@@ -76,7 +80,7 @@ new VueRouter({
76
80
It's also possible to turn of prefetching globally:
77
81
78
82
```js
79
-
Vue.use(RouterPrefetch, {
83
+
app.use(RouterPrefetch, {
80
84
prefetch:false
81
85
})
82
86
```
@@ -91,7 +95,7 @@ A list of additional files to prefetch. By default we only prefetch the route co
91
95
You can also set `meta.prefetchFiles` on vue-router's `route` object, it will be merged with the prop value:
0 commit comments