Skip to content

Commit 0b7ea94

Browse files
committed
Merge pull request #116 from JacobChang/chinese-documents
Chinese documents
2 parents 2cf7ef7 + d8476f5 commit 0b7ea94

35 files changed

+996
-0
lines changed

docs/LANGS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
* [English](en/)
22
* [日本語](ja/)
3+
* [中文](zh-cn/)

docs/zh-cn/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SUMMARY.md

docs/zh-cn/SUMMARY.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# vue-router文档 [![npm package](https://img.shields.io/npm/v/vue-router.svg)](https://www.npmjs.com/package/vue-router)
2+
3+
- [安装](installation.md)
4+
- [基本用法](basic.md)
5+
- [嵌套路由](nested.md)
6+
- [路由对象和路由匹配](route.md)
7+
- [路由配置项](options.md)
8+
- [router-view](view.md)
9+
- [v-link](link.md)
10+
- [切换控制流水线](pipeline/README.md)
11+
- [切换勾子函数](pipeline/hooks.md)
12+
- [data](pipeline/data.md)
13+
- [activate](pipeline/activate.md)
14+
- [deactivate](pipeline/deactivate.md)
15+
- [canActivate](pipeline/can-activate.md)
16+
- [canDeactivate](pipeline/can-deactivate.md)
17+
- [canReuse](pipeline/can-reuse.md)
18+
- [API](api/README.md)
19+
- [路由实例属性](api/properties.md)
20+
- [router.start](api/start.md)
21+
- [router.stop](api/stop.md)
22+
- [router.map](api/map.md)
23+
- [router.on](api/on.md)
24+
- [router.go](api/go.md)
25+
- [router.replace](api/replace.md)
26+
- [router.redirect](api/redirect.md)
27+
- [router.alias](api/alias.md)
28+
- [router.beforeEach](api/before-each.md)
29+
- [router.afterEach](api/after-each.md)

docs/zh-cn/api/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# API 索引
2+
3+
- [路由器实例属性](properties.md)
4+
- [router.start](start.md)
5+
- [router.stop](stop.md)
6+
- [router.map](map.md)
7+
- [router.on](on.md)
8+
- [router.go](go.md)
9+
- [router.replace](replace.md)
10+
- [router.redirect](redirect.md)
11+
- [router.alias](alias.md)
12+
- [router.beforeEach](before-each.md)
13+
- [router.afterEach](after-each.md)

docs/zh-cn/api/after-each.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# `router.afterEach(hook)`
2+
3+
设置全局的后置勾子函数,该函数会在每次路由切换**成功进入激活阶段**时被调用。
4+
5+
注意,该函数调用时仅仅意味着切换已经被验证过了,也就是所有 `canDeactivate``canActivate` 勾子函数都成功的被断定( resolved )了,而且浏览器地址栏中的地址也已经更新。并不能保证所有的 `activate` 勾子函数都被断定了。
6+
7+
注意,只能有一个全局的后置勾子函数。但是你可以在这个勾子函数内实现自己的中间件系统。
8+
9+
### 参数
10+
11+
- `hook {Function}`
12+
13+
此勾子函数一个类型为[切换对象](../pipeline/hooks.html#transition-object)的参数,但是你只能访问此参数的 `to``from` 属性, 这两个属性都是路由对象。在这个后置勾子函数里**不能**调用任何切换函数。
14+
15+
### Example
16+
17+
``` js
18+
router.afterEach(function (transition) {
19+
console.log('成功浏览到: ' + transition.to.path)
20+
})
21+
```

docs/zh-cn/api/alias.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# `router.alias(aliasMap)`
2+
3+
为路由器配置全局的别名规则。别名和重定向的区别在于,相对于重定向把 `fromPath` 替换为 `toPath` ,别名会保留 `fromPath` ,但是匹配时使用的是 `toPath`
4+
5+
例如,如果我们把 `/a` 取别名为 `/a/b/c` ,那么当我们访问 `/a` 时,浏览器地址栏中的URL会是 `/a` 。但是路由匹配是却像是在访问 `/a/b/c`
6+
7+
### 参数
8+
9+
- `aliasMap {Object}`
10+
11+
别名映射对象的格式应该为 `{ fromPath: toPath, ... }` 。路径中可以包含动态片段。
12+
13+
### Example
14+
15+
``` js
16+
router.alias({
17+
18+
// 匹配 /a 时就像是匹配 /a/b/c
19+
'/a': '/a/b/c',
20+
21+
// 别名可以包含动态片段
22+
// 而且重定向片段必须匹配
23+
'/user/:userId': '/user/profile/:userId'
24+
})
25+
```

docs/zh-cn/api/before-each.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# `router.beforeEach(hook)`
2+
3+
设置全局的前置勾子函数,这个函数会在路由切换开始时调用。调用发生在整个切换流水线之前。如果此钩子函数拒绝了切换,整个切换流水线根本就不会启动。
4+
5+
注意,只能有一个全局的前置勾子函数。但是你可以在这个勾子函数内实现自己的中间件系统。
6+
7+
### 参数
8+
9+
- `hook {Function}`
10+
11+
此勾子函数一个类型为[切换对象](../pipeline/hooks.html#transition-object)的参数。
12+
13+
### Example
14+
15+
简单示例
16+
17+
``` js
18+
router.beforeEach(function (transition) {
19+
if (transition.to.path === '/forbidden') {
20+
transition.abort()
21+
} else {
22+
transition.next()
23+
}
24+
})
25+
```
26+
27+
使用 Promise 和 ES6
28+
29+
``` js
30+
router.beforeEach(function ({ to, next }) {
31+
if (to.path === '/auth-required') {
32+
// 返回一个断定会 true 或者 false 的 Promise
33+
return AuthService.isLoggedIn()
34+
} else {
35+
next()
36+
}
37+
})
38+
```

docs/zh-cn/api/go.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# `router.go(path)`
2+
3+
导航到一个新的路由
4+
5+
### 参数
6+
7+
- `path: String`
8+
9+
此路径为一个普通路径(也就是说没有动态片段或者全匹配片段)。路径不能以 `/` 开头,会以相对于当前路径的方式进行解析。

docs/zh-cn/api/map.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# `router.map(routeMap)`
2+
3+
定义路由映射的主要方法。
4+
5+
### 参数
6+
7+
- `routeMap: Object`
8+
9+
结构体,键为路径,值为路由配置对象。对于路径匹配规则,查看[路由匹配](../route.html#route-matching).
10+
11+
### 路由配置对象
12+
13+
路由配置对象包含两个字段:
14+
15+
- `component`: 当路径匹配时,会渲染到顶级 `<router-view>` 的Vue组件。此字段的值可以是调用 `Vue.extend` 后返回的构造函数,或者普通的组件选项对象。在后一种情况下,路由会隐式调用 `Vue.extend`
16+
17+
- `subRoutes`: 嵌套的子路由映射。对于每一个 `subRoutes` 映射中的子路由对象,路由器在做匹配时会使用其路径拼接到父级路径后得到的全路径。成功匹配的组件会渲染到父级组件的 `<router-view>` 中。
18+
19+
### 例子
20+
21+
``` js
22+
router.map({
23+
// 组件构造函数
24+
'/a': {
25+
component: Vue.extend({ /* ... */ })
26+
},
27+
// 组件选项对象
28+
'/b': {
29+
component: {
30+
template: '<p>Hello from /b</p>'
31+
}
32+
},
33+
// 嵌套的路由
34+
'/c': {
35+
component: {
36+
// 渲染子视图
37+
template: '<router-view></router-view>'
38+
},
39+
subRoutes: {
40+
// 当路径是 /c/d 时进行渲染
41+
'/d': { component: { template: 'D' }},
42+
// 当路径是 /c/e 时进行渲染
43+
'/e': { component: { template: 'E' }}
44+
}
45+
}
46+
})
47+
```

docs/zh-cn/api/on.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# `router.on(path, config)`
2+
3+
添加一条顶级的路由配置。在内部实现时,`router.map()` 对于接收到的路由映射对象中每个键值对都调用 `router.on()`
4+
5+
### 参数
6+
7+
- `path: String` - 查看[路由匹配](../route.md#route-matching)
8+
- `config: Object` - 查看[路由配置对象](map.md#route-config-object).
9+
10+
### 例子
11+
12+
``` js
13+
router.on('/user/:userId', {
14+
component: {
15+
template: '<div>{{$route.params.userId}}</div>'
16+
}
17+
})
18+
```

0 commit comments

Comments
 (0)