Skip to content

Commit c677dff

Browse files
committed
chore: update readme
1 parent a9c916b commit c677dff

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

README.md

+12-8
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@
1616
yarn add vue-router-prefetch
1717
```
1818

19+
If you're using Vue 2, you should install `vue-router-prefetch@1` instead.
20+
1921
## Usage
2022

2123
You need to use this plugin after `vue-router`:
2224

2325
```js
24-
import Vue from 'vue'
25-
import Router from 'vue-router'
26+
import { createApp } from 'vue'
27+
import { createRouter } from 'vue-router'
2628
import RouterPrefetch from 'vue-router-prefetch'
2729

28-
Vue.use(Router)
29-
Vue.use(RouterPrefetch)
30+
const app = createApp()
31+
const router = createRouter()
32+
app.use(router)
33+
app.use(RouterPrefetch)
3034
```
3135

3236
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
3640
You can also register it as a new component instead of overriding `<router-link>`:
3741

3842
```js
39-
Vue.use(RouterPrefetch, {
43+
app.use(RouterPrefetch, {
4044
componentName: 'QuickLink'
4145
})
4246
```
@@ -62,7 +66,7 @@ Whether to prefetch the matched route component.
6266
You can also set `meta.prefetch` on vue-router's `route` object to disable prefetching this route for all `<router-link>`s:
6367

6468
```js
65-
new VueRouter({
69+
createRouter({
6670
routes: [
6771
{
6872
path: '/some-async-page',
@@ -76,7 +80,7 @@ new VueRouter({
7680
It's also possible to turn of prefetching globally:
7781

7882
```js
79-
Vue.use(RouterPrefetch, {
83+
app.use(RouterPrefetch, {
8084
prefetch: false
8185
})
8286
```
@@ -91,7 +95,7 @@ A list of additional files to prefetch. By default we only prefetch the route co
9195
You can also set `meta.prefetchFiles` on vue-router's `route` object, it will be merged with the prop value:
9296

9397
```js
94-
new VueRouter({
98+
createRouter({
9599
routes: [
96100
{
97101
path: '/some-async-page',

0 commit comments

Comments
 (0)