-
-
Notifications
You must be signed in to change notification settings - Fork 5k
docs($router): Note that router === this.$router #1687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
53593c7
f151ded
1039ff5
bd3ad27
f758551
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,27 @@ const app = new Vue({ | |
// Now the app has started! | ||
``` | ||
|
||
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: | ||
|
||
```js | ||
// Home.vue | ||
export default { | ||
computed: { | ||
params () { | ||
// We will see what params are shortly | ||
return this.$route.params | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be nice to update this to a more real-world example. For example: username () {
// We will see what params are shortly
return this.$route.params.username
} |
||
}, | ||
methods: { | ||
someMethod () { | ||
// Redirecting to another route | ||
this.$router.push('/redirect') | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, a more real-world example could be helpful, so that readers can begin imagining when they might use goBack () {
window.history.length > 1
? this.$router.go(-1)
: this.$router.push('/')
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another note: I'd probably avoid the word "redirect" here, as I think it implies an immediate transfer to another route in most cases - "navigate" or simple "go" are probably more appropriate. |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we're missing a |
||
``` | ||
|
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I'm actually wondering now if this paragraph is even necessary. I feel like the idea that
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder as well, let's share with the team There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the kind of text I'd put inside of a warning |
||
|
||
You can also checkout this example [live](http://jsfiddle.net/yyx990803/xgrjzsup/). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, thanks, I'll fix other _checkout_s as well but in another commit |
||
|
||
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). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gitbook transforms it automatically |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be
since
params
here refers to the attribute's name.