Skip to content

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

Merged
merged 5 commits into from
Oct 11, 2017
Merged

docs($router): Note that router === this.$router #1687

merged 5 commits into from
Oct 11, 2017

Conversation

posva
Copy link
Member

@posva posva commented Aug 15, 2017

No description provided.

@posva
Copy link
Member Author

posva commented Aug 15, 2017

@chrisvfritz Can I have your review on this, please?
More precisely, what do you think about introducing those note right at the beginning. Is it too early?

@connor11528
Copy link

The computed code block might not even be necessary though that is another great insight for getting params! Super helpful knowing we can refer to this.$router (a lot of the answers on the internets do things with this.$route as a legacy from vue 1.0)

@posva
Copy link
Member Author

posva commented Aug 15, 2017

@connor11528 That's a bit terrifying... It's a very basic feature. This means it's probably not clear in the docs 😞

// Redirecting to another route
this.$router.push('/redirect')
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we're missing a } here.

}
```

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoroughly -> Throughout

Copy link
Collaborator

Choose a reason for hiding this comment

The 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 router === this.$router is made clear by:

By injecting the router, we get access to it as this.$router

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder as well, let's share with the team

Copy link
Member Author

Choose a reason for hiding this comment

The 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 p

params () {
// We will see what params are shortly
return this.$route.params
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
}

someMethod () {
// Redirecting to another route
this.$router.push('/redirect')
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 this.$router. For example:

goBack () {
  window.history.length > 1
    ? this.$router.go(-1)
    : this.$router.push('/')
}

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

@posva
Copy link
Member Author

posva commented Aug 15, 2017

Thanks a lot for the nice review @chrisvfritz 🙂

export default {
computed: {
username () {
// We will see what params are shortly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be

// We will see what `params` is shortly

since params here refers to the attribute's name.

```

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.

You can also checkout this example [live](http://jsfiddle.net/yyx990803/xgrjzsup/).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be check out (with a space), as "checkout" is a noun.

Copy link
Member Author

Choose a reason for hiding this comment

The 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


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.

You can also check out this example [live](http://jsfiddle.net/yyx990803/xgrjzsup/).

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).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it router-link.md or router-link.html?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gitbook transforms it automatically

@posva posva added the docs label Oct 8, 2017
@yyx990803 yyx990803 merged commit a06e0b2 into dev Oct 11, 2017
@posva posva deleted the docs/router branch January 10, 2018 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants