From d7371c19f4d5dc9667989e307bdc1fc76269245b Mon Sep 17 00:00:00 2001 From: Connor Leech Date: Tue, 15 Aug 2017 12:13:53 -0700 Subject: [PATCH] add this.$router information Include information about the this.$router syntax. For many Vue.js projects vue-router will be configured in the main.js file and programmatic routes will be called from component files. This syntax is incredibly helpful and not obvious in the documentation. I found out about it because of [this thread](https://laracasts.com/discuss/channels/vue/redirect-from-method-in-vuejs-with-vue-router). Figured it should be accessible for all! Thank you --- docs/en/essentials/named-routes.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/en/essentials/named-routes.md b/docs/en/essentials/named-routes.md index 297457c52..ee2c47e9c 100644 --- a/docs/en/essentials/named-routes.md +++ b/docs/en/essentials/named-routes.md @@ -28,4 +28,10 @@ router.push({ name: 'user', params: { userId: 123 }}) In both cases, the router will navigate to the path `/user/123`. +Additionally, if you are in a separate component you can call these methods using `this.$router`. For example the above code can be rewritten in a component as: + +``` js +this.$router.push({ name: 'user', params: { userId: 123 }}) +``` + Full example [here](https://github.com/vuejs/vue-router/blob/dev/examples/named-routes/app.js).