0

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 } })
 } },

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.