Reputation: 5255
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
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