Skip to content

Commit bc9a7c6

Browse files
committed
docs: named routes & v-link changes
1 parent 9cd0c5e commit bc9a7c6

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

docs/en/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [Basic Usage](basic.md)
55
- [Nested Routes](nested.md)
66
- [Route Object & Route Matching](route.md)
7+
- [Named Routes](named.md)
78
- [Router Options](options.md)
89
- [router-view](view.md)
910
- [v-link](link.md)

docs/en/basic.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Creating a Single-page Application with Vue.js + vue-router is dead simple. With
99
<h1>Hello App!</h1>
1010
<p>
1111
<!-- use v-link directive for navigation. -->
12-
<a v-link="/foo">Go to Foo</a>
13-
<a v-link="/bar">Go to Bar</a>
12+
<a v-link="{ path: '/foo' }">Go to Foo</a>
13+
<a v-link="{ path: '/bar' }">Go to Bar</a>
1414
</p>
1515
<!-- route outlet -->
1616
<router-view></router-view>

docs/en/link.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
# v-link
22

3-
You should use the `v-link` directive for handling navigations inside a vue-router-enabled app for the following reasons:
3+
`v-link` is the directive for enabling user navigation in a router-enabled app. It accpets a JavaScript expression which will be passed to `router.go()` internally. For example:
4+
5+
``` html
6+
<!-- literal string -->
7+
<a v-link="'home'">Home</a>
8+
9+
<!-- same as above -->
10+
<a v-link="{ path: 'home' }">Home</a>
11+
12+
<!-- named route -->
13+
<a v-link="{ name: 'user', params: { userId: 123 }}">User</a>
14+
```
15+
16+
`v-link` is preferred over hard-coded `href` for the following reasons:
417

518
- It works the same way in both HTML5 history mode and hash mode, so if you ever decide to switch mode, or when the router falls back to hash mode in IE9, nothing needs to be changed.
619

@@ -21,5 +34,3 @@ The active link class name can be configured with the `activeLinkClass` option w
2134
#### Additional Notes
2235

2336
- `v-link` automatically sets the `href` attribute when used on an `<a>` element.
24-
25-
- Because `v-link` is a [literal directive](http://vuejs.org/guide/directives.html#Literal_Directives), it can contain mustache tags, e.g. `v-link="/user/{% raw %}{{user.name}}{% endraw %}"`.

docs/en/named.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Named Routes
2+
3+
Sometimes it is more convenient to identify a route with a name, especially when performing navigations. You can give a route a name in the route config like this:
4+
5+
``` js
6+
router.map({
7+
'/user/:userId': {
8+
name: 'user', // give the route a name
9+
component: { ... }
10+
}
11+
})
12+
```
13+
14+
To link to a named route, you can use `v-link` like this:
15+
16+
``` html
17+
<a v-link="{ name: 'user', params: { userId: 123 }}">User</a>
18+
```
19+
20+
You can also navigate to a named route programatically using `router.go()`:
21+
22+
``` js
23+
router.go({ name: 'user', params: { userId: 123 }})
24+
```
25+
26+
In both cases, the router will navigate to the path `/user/123`.

0 commit comments

Comments
 (0)