Skip to content

Commit a06e0b2

Browse files
posvayyx990803
authored andcommitted
docs: Note that router === this.$router (#1687)
* docs($router): Note that router === this.$router * docs($router): Chris review * docs($router): Phan review
1 parent c166822 commit a06e0b2

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Diff for: docs/en/essentials/getting-started.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,29 @@ const app = new Vue({
6565
// Now the app has started!
6666
```
6767

68-
You can also check out this example [live](https://jsfiddle.net/yyx990803/xgrjzsup/).
68+
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:
69+
70+
```js
71+
// Home.vue
72+
export default {
73+
computed: {
74+
username () {
75+
// We will see what `params` is shortly
76+
return this.$route.params.username
77+
}
78+
},
79+
methods: {
80+
goBack () {
81+
window.history.length > 1
82+
? this.$router.go(-1)
83+
: this.$router.push('/')
84+
}
85+
}
86+
}
87+
```
88+
89+
Throughout 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.
90+
91+
You can also check out this example [live](http://jsfiddle.net/yyx990803/xgrjzsup/).
6992

7093
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)