Skip to content

Commit 0775544

Browse files
author
leihaohao
committed
docs(README): 更新文档以适配 v1.0.0 新版本
1 parent f8eae37 commit 0775544

File tree

2 files changed

+89
-111
lines changed

2 files changed

+89
-111
lines changed

README.md

Lines changed: 45 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Lightweight Vue Router 4 plugin collection - extend routing capabilities with minimal overhead.
44

5+
> Starting from v1.0.0, the plugin is developed based on vue-router-plugin-system (the old plugin registration method is deprecated). See its documentation for details.
6+
57
[中文文档](./README.zh-CN.md)
68

79
[Online example](https://vue-spark.github.io/router-plugins/)
@@ -12,49 +14,25 @@ Lightweight Vue Router 4 plugin collection - extend routing capabilities with mi
1214
npm i @vue-spark/router-plugins
1315
```
1416

15-
### Full Registration
17+
### Plugin Registration
1618

1719
```ts
18-
import RouterPlugins from '@vue-spark/router-plugins'
19-
import { createRouter, createWebHistory } from 'vue-router'
20+
import ScrollerPlugin from '@vue-spark/router-plugins/scroller'
21+
import { createWebHistory } from 'vue-router'
22+
import { createRouter } from 'vue-router-plugin-system'
2023

2124
const router = createRouter({
2225
history: createWebHistory(),
2326
routes: [],
24-
})
25-
26-
// Recommend registering plugins immediately after creating the router instance
27-
// to prevent exceptions caused by other modules accessing the router before plugins load
28-
RouterPlugins(router, {
29-
// plugin options
30-
})
31-
32-
// Also supports registration via app
33-
app.use(RouterPlugins, {
34-
// plugin options
35-
})
36-
```
37-
38-
### Individual Registration
39-
40-
```ts
41-
import ScrollerPlugin from '@vue-spark/router-plugins/plugins/scroller'
42-
import { createRouter, createWebHistory } from 'vue-router'
43-
44-
const router = createRouter({
45-
history: createWebHistory(),
46-
routes: [],
47-
})
48-
49-
// Recommend registering plugins immediately after creating the router instance
50-
// to prevent exceptions caused by other modules accessing the router before plugins load
51-
RouterPlugins(ScrollerPlugin, {
52-
// plugin options
53-
})
54-
55-
// Also supports registration via app
56-
app.use(ScrollerPlugin, {
57-
// plugin options
27+
plugins: [
28+
// initialize the plugin
29+
ScrollerPlugin({
30+
selectors: {
31+
window: true,
32+
'.scrollable': true,
33+
},
34+
}),
35+
],
5836
})
5937
```
6038

@@ -262,7 +240,6 @@ Simulates mobile navigation direction (forward/backward/refresh) for animation a
262240
<Transition
263241
:name="transitionName"
264242
:css="!!transitionName"
265-
@after-enter="$router.scroller.trigger()"
266243
>
267244
<KeepAlive :include="[...keepAliveValues]">
268245
<Component
@@ -365,17 +342,23 @@ Automatically saves and restores scroll position for long pages or list pages.
365342
<summary>Usage Example</summary>
366343

367344
```ts
368-
// main.ts
369-
import ScrollerPlugin from '@vue-spark/router-plugins/plugins/scroller'
370-
import router from './router'
371-
372-
ScrollerPlugin(router, {
373-
// Scroll element selectors
374-
scroller: {
375-
window: true,
376-
body: true,
377-
'.scrollable': true,
378-
},
345+
// router/index.ts
346+
import ScrollerPlugin from '@vue-spark/router-plugins/scroller'
347+
import { createWebHistory } from 'vue-router'
348+
import { createRouter } from 'vue-router-plugin-system'
349+
350+
const router = createRouter({
351+
history: createWebHistory(),
352+
routes: [],
353+
plugins: [
354+
ScrollerPlugin({
355+
// set the selectors you want to use
356+
selectors: {
357+
window: true,
358+
'.scrollable': true,
359+
},
360+
}),
361+
],
379362
})
380363
```
381364

@@ -395,16 +378,12 @@ When using with `<Transition>`, manually trigger scroll restoration via `router.
395378

396379
#### Configuration Options
397380

398-
````ts
381+
```ts
399382
interface ScrollerOptions {
400383
/**
401-
* Scroll element selectors, supports special selector [window](file:///home/leihaohao/workspaces/own/vuespark/router-plugins/node_modules/.pnpm/[email protected]/node_modules/nice-fns/dist/index.d.ts#L339-L339)
402-
* @default
403-
* ```ts
404-
* { window: true, body: true }
405-
* ```
384+
* Scroll element selectors, supports special selector `window`
406385
*/
407-
selectors?: Record<string, boolean | ScrollHandler>
386+
selectors: Record<string, boolean | ScrollHandler>
408387
/**
409388
* Scroll behavior
410389
*/
@@ -416,7 +395,7 @@ interface ScrollerOptions {
416395
*/
417396
scrollOnlyBackward?: boolean
418397
}
419-
````
398+
```
420399

421400
#### Type Definitions
422401

@@ -509,3 +488,12 @@ interface Router {
509488
previousRoute: ShallowRef<PreviousRoute | undefined>
510489
}
511490
```
491+
492+
## Migration Guide
493+
494+
### From v0.x to v1.x
495+
496+
- Remove all plugin registration shorthands, only support on-demand importing required plugins.
497+
- Plugins are developed based on vue-router-plugin-system (old plugin registration method is deprecated). See its documentation for details.
498+
- Single plugin import path changed to `@vue-spark/router-plugins/[plugin-name]`.
499+
- `selectors` configuration item in ScrollerPlugin has no default value and is now required.

README.zh-CN.md

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
轻量级 Vue Router 4 插件集合——以最小开销扩展路由能力。
44

5+
> `v1.0.0` 起,插件基于 [vue-router-plugin-system](https://github.com/vue-spark/vue-router-plugin-system) 开发(弃用旧插件注册方式),详见其文档。
6+
57
[English Document](./README.md)
68

79
[在线示例](https://vue-spark.github.io/router-plugins/)
@@ -12,47 +14,25 @@
1214
npm i @vue-spark/router-plugins
1315
```
1416

15-
### 全部注册
17+
### 插件注册
1618

1719
```ts
18-
import RouterPlugins from '@vue-spark/router-plugins'
19-
import { createRouter, createWebHistory } from 'vue-router'
20+
import ScrollerPlugin from '@vue-spark/router-plugins/scroller'
21+
import { createWebHistory } from 'vue-router'
22+
import { createRouter } from 'vue-router-plugin-system'
2023

2124
const router = createRouter({
2225
history: createWebHistory(),
2326
routes: [],
24-
})
25-
26-
// 建议在创建 router 实例后立即注册插件,防止其他模块在插件加载前访问 router 实例导致异常
27-
RouterPlugins(router, {
28-
// 插件配置项
29-
})
30-
31-
// 也支持通过 app 注册
32-
app.use(RouterPlugins, {
33-
// 插件配置项
34-
})
35-
```
36-
37-
### 单个注册
38-
39-
```ts
40-
import ScrollerPlugin from '@vue-spark/router-plugins/plugins/scroller'
41-
import { createRouter, createWebHistory } from 'vue-router'
42-
43-
const router = createRouter({
44-
history: createWebHistory(),
45-
routes: [],
46-
})
47-
48-
// 建议在创建 router 实例后立即注册插件,防止其他模块在插件加载前访问 router 实例导致异常
49-
RouterPlugins(ScrollerPlugin, {
50-
// 插件配置项
51-
})
52-
53-
// 也支持通过 app 注册
54-
app.use(ScrollerPlugin, {
55-
// 插件配置项
27+
plugins: [
28+
// 初始化插件
29+
ScrollerPlugin({
30+
selectors: {
31+
window: true,
32+
'.scrollable': true,
33+
},
34+
}),
35+
],
5636
})
5737
```
5838

@@ -258,7 +238,6 @@ interface Router {
258238
<Transition
259239
:name="transitionName"
260240
:css="!!transitionName"
261-
@after-enter="$router.scroller.trigger()"
262241
>
263242
<KeepAlive :include="[...keepAliveValues]">
264243
<Component
@@ -360,17 +339,23 @@ interface Router {
360339
<summary>使用示例</summary>
361340

362341
```ts
363-
// main.ts
364-
import ScrollerPlugin from '@vue-spark/router-plugins/plugins/scroller'
365-
import router from './router'
366-
367-
ScrollerPlugin(router, {
368-
// 设置滚动位置的元素选择器
369-
scroller: {
370-
window: true,
371-
body: true,
372-
'.scrollable': true,
373-
},
342+
// router/index.ts
343+
import ScrollerPlugin from '@vue-spark/router-plugins/scroller'
344+
import { createWebHistory } from 'vue-router'
345+
import { createRouter } from 'vue-router-plugin-system'
346+
347+
const router = createRouter({
348+
history: createWebHistory(),
349+
routes: [],
350+
plugins: [
351+
ScrollerPlugin({
352+
// 设置滚动目标
353+
selectors: {
354+
window: true,
355+
'.scrollable': true,
356+
},
357+
}),
358+
],
374359
})
375360
```
376361

@@ -390,16 +375,12 @@ ScrollerPlugin(router, {
390375

391376
#### 配置项
392377

393-
````ts
378+
```ts
394379
interface ScrollerOptions {
395380
/**
396381
* 滚动元素选择器,支持特殊选择器 `window`
397-
* @default
398-
* ```ts
399-
* { window: true, body: true }
400-
* ```
401382
*/
402-
selectors?: Record<string, boolean | ScrollHandler>
383+
selectors: Record<string, boolean | ScrollHandler>
403384
/**
404385
* 滚动行为
405386
*/
@@ -411,7 +392,7 @@ interface ScrollerOptions {
411392
*/
412393
scrollOnlyBackward?: boolean
413394
}
414-
````
395+
```
415396

416397
#### 类型定义
417398

@@ -503,3 +484,12 @@ interface Router {
503484
previousRoute: ShallowRef<PreviousRoute | undefined>
504485
}
505486
```
487+
488+
## 迁移指南
489+
490+
### v0.x 迁移至 v1.x
491+
492+
- 移除全部插件注册快捷方式,仅支持按需导入需要注册的插件。
493+
- 插件基于 [vue-router-plugin-system](https://github.com/vue-spark/vue-router-plugin-system) 开发(弃用旧插件注册方式),详见其文档。
494+
- 单一插件导入路径改为 `@vue-spark/router-plugins/[plugin-name]`
495+
- ScrollerPlugin 配置项 `selectors` 移除默认值并改为必填项。

0 commit comments

Comments
 (0)