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?
Adding dynamic routes in VueUpdate the router/index. js file with the new route in the routes array. Remember to include the import for the Post component. Restart your app and head to localhost:8080/post/dynamic-routing in your browser.
You can pass parameters to the router by using this syntax:
edit: function(joke) {
this.$router.push('/edit/' + joke.id)
}
If you have named your route you can use this syntax instead:
edit: function(joke) {
this.$router.push({ name: 'edit', params: { id: joke.id }})
}
Read more about programmatic navigation with Vue Router here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With