You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/README.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ We will be using [ES2015](https://github.com/lukehoban/es6features) in the code
6
6
Also, all examples will be using the full version of Vue to make on-the-fly template compilation possible. See more details [here](https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only).
7
7
:::
8
8
9
-
<divclass="vueschool"><ahref="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">Watch a free video course about Vue Router on Vue School</a></div>
9
+
<divclass="vueschool"><ahref="https://vueschool.io/courses/vue-router-for-everyone?friend=vuerouter"target="_blank"rel="sponsored noopener"title="Learn how to build powerful Single Page Applications with the Vue Router on Vue School">Watch a free video course about Vue Router on Vue School</a></div>
10
10
11
11
Creating a Single-page Application with Vue + Vue Router feels natural: with Vue.js, we are already composing our application with 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:
Copy file name to clipboardExpand all lines: docs/guide/advanced/lazy-loading.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Lazy Loading Routes
2
2
3
-
<divclass="vueschool"><ahref="https://vueschool.io/lessons/how-to-lazy-load-routes-with-vue-router?friend=vuejs"target="_blank"rel="sponsored noopener"title="Learn how to increase performance by lazy loading routes on Vue School">Learn how to lazy load routes with a free lesson on Vue School</a></div>
3
+
<divclass="vueschool"><ahref="https://vueschool.io/lessons/how-to-lazy-load-routes-with-vue-router?friend=vuerouter"target="_blank"rel="sponsored noopener"title="Learn how to increase performance by lazy loading routes on Vue School">Learn how to lazy load routes with a free lesson on Vue School</a></div>
4
4
5
5
When building apps with a bundler, the JavaScript bundle can become quite large, and thus affect the page load time. It would be more efficient if we can split each route's components into a separate chunk, and only load them when the route is visited.
Copy file name to clipboardExpand all lines: docs/guide/advanced/navigation-guards.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Remember that **params or query changes won't trigger enter/leave navigation gua
6
6
7
7
## Global Before Guards
8
8
9
-
<divclass="vueschool"><ahref="https://vueschool.io/lessons/how-to-configure-an-authentication-middleware-route-guard-with-vue-router?friend=vuejs"target="_blank"rel="sponsored noopener"title="Learn how to create an authentication middleware with a global route guard on Vue School">Learn how navigation guards works with a free lesson on Vue School</a></div>
9
+
<divclass="vueschool"><ahref="https://vueschool.io/lessons/how-to-configure-an-authentication-middleware-route-guard-with-vue-router?friend=vuerouter"target="_blank"rel="sponsored noopener"title="Learn how to create an authentication middleware with a global route guard on Vue School">Learn how navigation guards works with a free lesson on Vue School</a></div>
10
10
11
11
You can register global before guards using `router.beforeEach`:
12
12
@@ -100,20 +100,20 @@ Finally, you can directly define route navigation guards inside route components
100
100
```js
101
101
constFoo= {
102
102
template:`...`,
103
-
beforeRouteEnter(to, from, next) {
103
+
beforeRouteEnter(to, from, next) {
104
104
// called before the route that renders this component is confirmed.
105
105
// does NOT have access to `this` component instance,
106
106
// because it has not been created yet when this guard is called!
107
107
},
108
-
beforeRouteUpdate(to, from, next) {
108
+
beforeRouteUpdate(to, from, next) {
109
109
// called when the route that renders this component has changed.
110
110
// This component being reused (by using an explicit `key`) in the new route or not doesn't change anything.
111
111
// For example, for a route with dynamic params `/foo/:id`, when we
112
112
// navigate between `/foo/1` and `/foo/2`, the same `Foo` component instance
113
113
// will be reused (unless you provided a `key` to `<router-view>`), and this hook will be called when that happens.
114
114
// has access to `this` component instance.
115
115
},
116
-
beforeRouteLeave(to, from, next) {
116
+
beforeRouteLeave(to, from, next) {
117
117
// called when the route that renders this component is about to
Note that `beforeRouteEnter` is the only guard that supports passing a callback to `next`. For `beforeRouteUpdate` and `beforeRouteLeave`, `this` is already available, so passing a callback is unnecessary and therefore *not supported*:
136
+
Note that `beforeRouteEnter` is the only guard that supports passing a callback to `next`. For `beforeRouteUpdate` and `beforeRouteLeave`, `this` is already available, so passing a callback is unnecessary and therefore _not supported_:
137
137
138
138
```js
139
139
beforeRouteUpdate (to, from, next) {
@@ -162,7 +162,7 @@ If you are using mixins that add in-component navigation guards, make sure to ad
Copy file name to clipboardExpand all lines: docs/guide/advanced/scroll-behavior.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
1
# Scroll Behavior
2
2
3
-
<divclass="vueschool"><ahref="https://vueschool.io/lessons/how-to-control-the-scroll-behavior-of-vue-router?friend=vuejs"target="_blank"rel="sponsored noopener"title="Learn how to control the scroll behavior on Vue School">Learn to control the scroll behavior with a free lesson on Vue School</a></div>
3
+
<divclass="vueschool"><ahref="https://vueschool.io/lessons/how-to-control-the-scroll-behavior-of-vue-router?friend=vuerouter"target="_blank"rel="sponsored noopener"title="Learn how to control the scroll behavior on Vue School">Learn to control the scroll behavior with a free lesson on Vue School</a></div>
4
4
5
5
When using client-side routing, we may want to scroll to top when navigating to a new route, or preserve the scrolling position of history entries just like real page reload does. `vue-router` allows you to achieve these and even better, allows you to completely customize the scroll behavior on route navigation.
6
6
7
7
**Note: this feature only works if the browser supports `history.pushState`.**
8
8
9
9
When creating the router instance, you can provide the `scrollBehavior` function:
10
10
11
-
```js
11
+
```js
12
12
constrouter=newVueRouter({
13
13
routes: [...],
14
14
scrollBehavior (to, from, savedPosition) {
@@ -28,7 +28,7 @@ If a falsy value or an empty object is returned, no scrolling will happen.
28
28
29
29
For example:
30
30
31
-
```js
31
+
```js
32
32
scrollBehavior (to, from, savedPosition) {
33
33
return { x:0, y:0 }
34
34
}
@@ -38,7 +38,7 @@ This will simply make the page scroll to top for all route navigations.
38
38
39
39
Returning the `savedPosition` will result in a native-like behavior when navigating with back/forward buttons:
Copy file name to clipboardExpand all lines: docs/guide/advanced/transitions.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# Transitions
2
2
3
-
<divclass="vueschool"><ahref="https://vueschool.io/lessons/how-to-create-route-transitions-with-vue-router?friend=vuejs"target="_blank"rel="sponsored noopener"title="Learn how to create route transitions on Vue School">Learn how to create route transitions with a free lesson on Vue School</a></div>
3
+
<divclass="vueschool"><ahref="https://vueschool.io/lessons/how-to-create-route-transitions-with-vue-router?friend=vuerouter"target="_blank"rel="sponsored noopener"title="Learn how to create route transitions on Vue School">Learn how to create route transitions with a free lesson on Vue School</a></div>
4
4
5
5
Since the `<router-view>` is essentially a dynamic component, we can apply transition effects to it the same way using the `<transition>` component:
6
6
7
-
```html
7
+
```html
8
8
<transition>
9
9
<router-view></router-view>
10
10
</transition>
@@ -16,7 +16,7 @@ Since the `<router-view>` is essentially a dynamic component, we can apply trans
16
16
17
17
The above usage will apply the same transition for all routes. If you want each route's component to have different transitions, you can instead use `<transition>` with different names inside each route component:
18
18
19
-
```js
19
+
```js
20
20
constFoo= {
21
21
template:`
22
22
<transition name="slide">
@@ -38,14 +38,14 @@ const Bar = {
38
38
39
39
It is also possible to determine the transition to use dynamically based on the relationship between the target route and current route:
40
40
41
-
```html
41
+
```html
42
42
<!-- use a dynamic transition name -->
43
43
<transition:name="transitionName">
44
44
<router-view></router-view>
45
45
</transition>
46
46
```
47
47
48
-
```js
48
+
```js
49
49
// then, in the parent component,
50
50
// watch the `$route` to determine the transition to use
Copy file name to clipboardExpand all lines: docs/guide/essentials/dynamic-matching.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Dynamic Route Matching
2
2
3
-
<divclass="vueschool"><ahref="https://vueschool.io/lessons/vue-router-dynamic-routes?friend=vuejs"target="_blank"rel="sponsored noopener"title="Learn how to match dynamic routes with Vue School">Learn how to match dynamic routes with a free lesson on Vue School</a></div>
3
+
<divclass="vueschool"><ahref="https://vueschool.io/lessons/vue-router-dynamic-routes?friend=vuerouter"target="_blank"rel="sponsored noopener"title="Learn how to match dynamic routes with Vue School">Learn how to match dynamic routes with a free lesson on Vue School</a></div>
4
4
5
5
Very often we will need to map routes with the given pattern to the same component. For example we may have a `User` component which should be rendered for all users but with different user IDs. In `vue-router` we can use a dynamic segment in the path to achieve that:
6
6
@@ -60,7 +60,7 @@ Or, use the `beforeRouteUpdate` [navigation guard](../advanced/navigation-guards
Copy file name to clipboardExpand all lines: docs/guide/essentials/named-routes.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# Named Routes
2
2
3
-
<divclass="vueschool"><ahref="https://vueschool.io/lessons/vue-router-named-routes-and-params?friend=vuejs"target="_blank"rel="sponsored noopener"title="Learn how to work with named routes and params with Vue School">Learn how to use named routes and params with a free lesson on Vue School</a></div>
3
+
<divclass="vueschool"><ahref="https://vueschool.io/lessons/vue-router-named-routes-and-params?friend=vuerouter"target="_blank"rel="sponsored noopener"title="Learn how to work with named routes and params with Vue School">Learn how to use named routes and params with a free lesson on Vue School</a></div>
4
4
5
5
Sometimes it is more convenient to identify a route with a name, especially when linking to a route or performing navigations. You can give a route a name in the `routes` options while creating the Router instance:
6
6
7
-
```js
7
+
```js
8
8
constrouter=newVueRouter({
9
9
routes: [
10
10
{
@@ -18,14 +18,14 @@ const router = new VueRouter({
18
18
19
19
To link to a named route, you can pass an object to the `router-link` component's `to` prop:
Copy file name to clipboardExpand all lines: docs/guide/essentials/nested-routes.md
+13-12
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Nested Routes
2
2
3
-
<divclass="vueschool"><ahref="https://vueschool.io/lessons/vue-router-nested-routes?friend=vuejs"target="_blank"rel="sponsored noopener"title="Learn how to work with nested routes with Vue School">Learn how to work with nested routes with a free lesson on Vue School</a></div>
3
+
<divclass="vueschool"><ahref="https://vueschool.io/lessons/vue-router-nested-routes?friend=vuerouter"target="_blank"rel="sponsored noopener"title="Learn how to work with nested routes with Vue School">Learn how to work with nested routes with a free lesson on Vue School</a></div>
4
4
5
5
Real app UIs are usually composed of components that are nested multiple levels deep. It is also very common that the segments of a URL corresponds to a certain structure of nested components, for example:
6
6
@@ -19,27 +19,25 @@ With `vue-router`, it is very simple to express this relationship using nested r
19
19
20
20
Given the app we created in the last chapter:
21
21
22
-
```html
22
+
```html
23
23
<divid="app">
24
24
<router-view></router-view>
25
25
</div>
26
26
```
27
27
28
-
```js
28
+
```js
29
29
constUser= {
30
30
template:'<div>User {{ $route.params.id }}</div>'
31
31
}
32
32
33
33
constrouter=newVueRouter({
34
-
routes: [
35
-
{ path:'/user/:id', component: User }
36
-
]
34
+
routes: [{ path:'/user/:id', component: User }]
37
35
})
38
36
```
39
37
40
38
The `<router-view>` here is a top-level outlet. It renders the component matched by a top level route. Similarly, a rendered component can also contain its own, nested `<router-view>`. For example, if we add one inside the `User` component's template:
41
39
42
-
```js
40
+
```js
43
41
constUser= {
44
42
template:`
45
43
<div class="user">
@@ -52,10 +50,12 @@ const User = {
52
50
53
51
To render components into this nested outlet, we need to use the `children` option in `VueRouter` constructor config:
54
52
55
-
```js
53
+
```js
56
54
constrouter=newVueRouter({
57
55
routes: [
58
-
{ path:'/user/:id', component: User,
56
+
{
57
+
path:'/user/:id',
58
+
component: User,
59
59
children: [
60
60
{
61
61
// UserProfile will be rendered inside User's <router-view>
@@ -81,15 +81,16 @@ As you can see the `children` option is just another Array of route configuratio
81
81
82
82
At this point, with the above configuration, when you visit `/user/foo`, nothing will be rendered inside `User`'s outlet, because no sub route is matched. Maybe you do want to render something there. In such case you can provide an empty subroute path:
83
83
84
-
```js
84
+
```js
85
85
constrouter=newVueRouter({
86
86
routes: [
87
87
{
88
-
path:'/user/:id', component: User,
88
+
path:'/user/:id',
89
+
component: User,
89
90
children: [
90
91
// UserHome will be rendered inside User's <router-view>
Copy file name to clipboardExpand all lines: docs/guide/essentials/passing-props.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Passing Props to Route Components
2
2
3
-
<divclass="vueschool"><ahref="https://vueschool.io/lessons/how-to-pass-vue-router-params-as-props-to-components?friend=vuejs"target="_blank"rel="sponsored noopener"title="Learn how to pass props to route components with Vue School">Learn how to pass props to route components with a free lesson on Vue School</a></div>
3
+
<divclass="vueschool"><ahref="https://vueschool.io/lessons/how-to-pass-vue-router-params-as-props-to-components?friend=vuerouter"target="_blank"rel="sponsored noopener"title="Learn how to pass props to route components with Vue School">Learn how to pass props to route components with a free lesson on Vue School</a></div>
4
4
5
5
Using `$route` in your component creates a tight coupling with the route which limits the flexibility of the component as it can only be used on certain URLs.
<divclass="vueschool"><ahref="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">Watch a free video course about Vue Router on Vue School</a></div>
9
+
<divclass="vueschool"><ahref="https://vueschool.io/courses/vue-router-for-everyone?friend=vuerouter"target="_blank"rel="sponsored noopener"title="Learn how to build powerful Single Page Applications with the Vue Router on Vue School">Watch a free video course about Vue Router on Vue School</a></div>
すべての example では、vue の完全バージョンを使用してテンプレートを解析可能にしています。詳細は[こちら](https://jp.vuejs.org/v2/guide/installation.html#ランタイム-コンパイラとランタイム限定の違い)を参照してください。
7
7
:::
8
8
9
-
<divclass="vueschool"><ahref="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">Watch a free video course about Vue Router on Vue School</a></div>
9
+
<divclass="vueschool"><ahref="https://vueschool.io/courses/vue-router-for-everyone?friend=vuerouter"target="_blank"rel="sponsored noopener"title="Learn how to build powerful Single Page Applications with the Vue Router on Vue School">Watch a free video course about Vue Router on Vue School</a></div>
0 commit comments