Skip to content

Commit 15865e9

Browse files
committed
docs wip
1 parent 3268b08 commit 15865e9

File tree

8 files changed

+114
-12
lines changed

8 files changed

+114
-12
lines changed

docs/SUMMARY.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@
22

33
- [Installation](installation.md)
44
- [Basic Usage](basic.md)
5+
- [Nested Routes](nested.md)
6+
- [Route Context](route.md)
7+
- [v-link](link.md)
58
- [Router Options](options.md)
6-
- [Top Level API](api/README.md)
9+
- Transition Pipeline
10+
- [Overview](pipeline/README.md)
11+
- [Transition Object](pipeline/transition.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 Reference
719
- [router.map](api/map.md)
820
- [router.on](api/on.md)
921
- [router.redirect](api/redirect.md)
@@ -13,10 +25,3 @@
1325
- [router.replace](api/replace.md)
1426
- [router.start](api/start.md)
1527
- [router.stop](api/stop.md)
16-
- [View Lifecycle Configuration](config/README.md)
17-
- [data](config/data.md)
18-
- [activate](config/activate.md)
19-
- [deactivate](config/deactivate.md)
20-
- [canActivate](config/can-activate.md)
21-
- [canDeactivate](config/can-deactivate.md)
22-
- [canReuse](config/can-reuse.md)

docs/basic.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,60 @@
11
# Basic Usage
22

3-
TODO
3+
Creating a Single-page Application with Vue.js + vue-router is dead simple. With Vue.js, we are already breaking our application into components. When adding vue-router to the mix, all we need to do is map our components to the routes and let vue-router know where to render them. Here's a basic example:
4+
5+
### HTML
6+
7+
``` html
8+
<div id="app">
9+
<h1>Hello App!</h1>
10+
<p>
11+
<!-- use v-link directive for navigation. -->
12+
<a v-link="/foo">Go to Foo</a>
13+
<a v-link="/bar">Go to Bar</a>
14+
</p>
15+
<!-- route outlet -->
16+
<router-view></router-view>
17+
</div>
18+
```
19+
20+
### JavaScript
21+
22+
``` js
23+
// define some components
24+
var Foo = Vue.extend({
25+
template: '<p>This is foo!</p>'
26+
})
27+
28+
var Bar = Vue.extend({
29+
template: '<p>This is bar!</p>'
30+
})
31+
32+
// the router needs a root component to render.
33+
// for demo purposes, we will just use an empty one
34+
// because we are using the HTML as the app template.
35+
var App = Vue.extend({})
36+
37+
// create a router instance.
38+
// you can pass in additional options here, but let's
39+
// keep it simple for now.
40+
var router = new VueRouter()
41+
42+
// define some routes.
43+
// each route should map to a component.
44+
// we'll talk about nested routes later.
45+
router.map({
46+
'/foo': {
47+
component: Foo
48+
},
49+
'/bar': {
50+
component: Bar
51+
}
52+
})
53+
54+
// now we can start the app!
55+
// router will create an instance of App and mount to
56+
// the element matching the selector #app.
57+
router.start(App, '#app')
58+
```
59+
60+
You can also checkout this example [live](http://jsfiddle.net/yyx990803/xyu276sa/).

docs/installation.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ npm install vue-router
1212
npm install vuejs/vue-router#dev
1313
```
1414

15+
When used in CommonJS, you must explicitly install the router via `Vue.use()`:
16+
17+
``` js
18+
var Vue = require('vue')
19+
var VueRouter = require('vue-router')
20+
21+
Vue.use(VueRouter)
22+
```
23+
24+
You don't need to do this when using the standalone build because it installs itself automatically.
25+
1526
### Bower
1627

1728
``` bash

docs/link.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# v-link

docs/nested.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Nested Routes

docs/options.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
# Router Options
2-
3-
TODO
1+
# Route Options

docs/pipeline/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Transition Pipeline
2+
3+
Route components can configure its transition and data-loading behavior by implementing appropriate transition pipeline hooks. These hooks include:
4+
5+
- `data`
6+
- `activate`
7+
- `deactivate`
8+
- `canActivate`
9+
- `canDeactivate`
10+
- `canReuse`
11+
12+
When a route transition is triggered, these hooks will be called in a specific order on affected view components.
13+
14+
A route transition can be divided into three phases:
15+
16+
1. **Reusability phase:**
17+
18+
Check if any component in the current view hierarchy can be reused in the new one.
19+
20+
2. **Validation phase:**
21+
22+
Check if all current components can be deactivated, and if all new components can be activated.
23+
24+
3. **Activation phase:**
25+
26+
Deactivate current components and activate new components.
27+
28+
The diagram below demonstrates the full pipeline of a route transition:

docs/route.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Route Context

0 commit comments

Comments
 (0)