Skip to content

Commit 53593c7

Browse files
committed
docs($router): Note that router === this.$router
1 parent b06ea21 commit 53593c7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/en/essentials/getting-started.md

+21
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,27 @@ const app = new Vue({
6464
// Now the app has started!
6565
```
6666

67+
By injecting the router, we get access to it as `this.$router` as well as the current route as `this.$route` inside of any component:
68+
69+
```js
70+
// Home.vue
71+
export default {
72+
computed: {
73+
params () {
74+
// We will see what params are shortly
75+
return this.$route.params
76+
}
77+
},
78+
methods: {
79+
someMethod () {
80+
// Redirecting to another route
81+
this.$router.push('/redirect')
82+
}
83+
}
84+
```
85+
86+
Thoroughly the docs, we will often use the `router` instance. Keep in mind that `this.$router` is exactly the same as using `router`. The reason we use `this.$router` is because we don't want to import the router in every single component that needs to manipulate routing.
87+
6788
You can also checkout this example [live](http://jsfiddle.net/yyx990803/xgrjzsup/).
6889
6990
Notice that a `<router-link>` automatically gets the `.router-link-active` class when its target route is matched. You can learn more about it in its [API reference](../api/router-link.md).

0 commit comments

Comments
 (0)