Kendall
Kendall

Reputation: 5255

set VueComponent properties via VueRouter

Can I set properties of a VueComponent via the VueRouter?

I have a couple routes

{ path: '/user/:id/budgets', component: Budgets },
{ path: '/budgets', component: Budgets }

Both us the same component but will get completely different record set bases on the routes....

The thing is the action is controlled by a property ..... Can set property values from the route?

 { path: '/user/:id/budgets', component: function(id){
return Vue.extend(Budgets, { props: { id: id } })
 } },

Upvotes: 0

Views: 221

Answers (1)

K3TH3R
K3TH3R

Reputation: 759

Vue-Router allows you to access all of the Route's current properties from within every component using this.$route, so you wouldn't be setting the properties so much as fetching them from within the component's reference to the router. You should be able to get your ID parameter from within your component by doing something like: this.$route.params.id.

The Data Fetching portion of the Vue-Router docs has a good example of this in action.

Upvotes: 1

Related Questions