Skip to content

Commit c128b60

Browse files
authored
docs(zh): update (#3446)
1 parent 97c8dae commit c128b60

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

Diff for: docs/zh/api/README.md

+54
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,26 @@ sidebar: auto
321321

322322
当前路由对应的[路由信息对象](#路由对象)
323323

324+
### router.START_LOCATION
325+
326+
- 类型:`Route`
327+
328+
[路由对象](#路由对象)的格式展示初始路由地址,即路由开始的地方。可用在导航守卫中以区分初始导航。
329+
330+
```js
331+
import Router from 'vue-router'
332+
333+
const router = new Router({
334+
// ...
335+
})
336+
337+
router.beforeEach((to, from) => {
338+
if (from === START_LOCATION) {
339+
// 初始导航
340+
}
341+
})
342+
```
343+
324344
## Router 实例方法
325345

326346
### router.beforeEach
@@ -371,6 +391,8 @@ router.forward()
371391
372392
动态的导航到一个新 URL。参考[编程式导航](../guide/essentials/navigation.md)。
373393
394+
这些函数仅在安装路由插件并将其传递给 Vue 根实例后调用,如[起步](../guide/README.md)所示。
395+
374396
### router.getMatchedComponents
375397
376398
函数签名:
@@ -400,6 +422,8 @@ const resolved: {
400422
401423
### router.addRoutes
402424
425+
*已废弃*:使用 [`route.addRoute()`](#router-addroute) 代替。
426+
403427
函数签名:
404428
405429
```js
@@ -408,6 +432,36 @@ router.addRoutes(routes: Array<RouteConfig>)
408432
409433
动态添加更多的路由规则。参数必须是一个符合 `routes` 选项要求的数组。
410434
435+
### router.addRoute
436+
437+
添加一条新路由规则。如果该路由规则有 `name`,并且已经存在一个与之相同的名字,则会覆盖它。
438+
439+
函数签名:
440+
441+
```ts
442+
addRoute(route: RouteConfig): () => void
443+
```
444+
445+
### router.addRoute
446+
447+
添加一条新的路由规则记录作为现有路由的子路由。如果该路由规则有 `name`,并且已经存在一个与之相同的名字,则会覆盖它。
448+
449+
函数签名:
450+
451+
```ts
452+
addRoute(parentName: string, route: RouteConfig): () => void
453+
```
454+
455+
### router.getRoutes
456+
457+
获取所有活跃的路由记录列表。**注意只有文档中记录下来的 property 才被视为公共 API**,避免使用任何其它 property,例如 `regex`,因为它在 Vue Router 4 中不存在。
458+
459+
函数签名:
460+
461+
```ts
462+
getRoutes(): RouteRecord[]
463+
```
464+
411465
### router.onReady
412466
413467
函数签名:

Diff for: docs/zh/guide/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<div class="vueschool"><a href="https://vueschool.io/courses/vue-router-for-everyone?friend=vuejs" target="_blank" rel="sponsored noopener" title="Learn how to build powerful Single Page Applications with the Vue Router on Vue School">观看 Vue School 的关于 Vue Router 的免费视频课程 (英文)</a></div>
1010

11-
用 Vue.js + Vue Router 创建单页应用,是非常简单的。使用 Vue.js ,我们已经可以通过组合组件来组成应用程序,当你要把 Vue Router 添加进来,我们需要做的是,将组件 (components) 映射到路由 (routes),然后告诉 Vue Router 在哪里渲染它们。下面是个基本例子:
11+
用 Vue.js + Vue Router 创建单页应用,感觉很自然:使用 Vue.js ,我们已经可以通过组合组件来组成应用程序,当你要把 Vue Router 添加进来,我们需要做的是,将组件 (components) 映射到路由 (routes),然后告诉 Vue Router 在哪里渲染它们。下面是个基本例子:
1212

1313
## HTML
1414

Diff for: docs/zh/guide/advanced/scroll-behavior.md

+15
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,18 @@ scrollBehavior (to, from, savedPosition) {
7979
```
8080

8181
将其挂载到从页面级别的过渡组件的事件上,令其滚动行为和页面过渡一起良好运行是可能的。但是考虑到用例的多样性和复杂性,我们仅提供这个原始的接口,以支持不同用户场景的具体实现。
82+
83+
## 平滑滚动
84+
85+
只需将 `behavior` 选项添加到 `scrollBehavior` 内部返回的对象中,就可以为[支持它的浏览器](https://developer.mozilla.org/en-US/docs/Web/API/ScrollToOptions/behavior)启用原生平滑滚动:
86+
87+
```js
88+
scrollBehavior (to, from, savedPosition) {
89+
if (to.hash) {
90+
return {
91+
selector: to.hash,
92+
behavior: 'smooth',
93+
}
94+
}
95+
}
96+
```

0 commit comments

Comments
 (0)