Skip to content
Advertisement

How to pass parameter to vue.js router in a method function?

I’m trying to send ‘joke.id’ as parameter to the router:

edit: function(joke) {
    this.$router.push({ '/edit/' + joke.id }); 
}

The relevant route is:

{path: '/edit/:id', component: editJoke, name: 'editJoke'},

However I get this in the console:

Module build failed: SyntaxError: Unexpected token

this.$router.push({ '/edit/' + joke.id }); 
  |                          ^

How can I fix this?

Advertisement

Answer

There’s no need for curly braces inside the push function. Your code should be like this:

this.$router.push('/edit/' + joke.id); 
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement