Reputation: 5939
I have a button like this:
<router-link :to="{path: '/foo/bar', params: {id: 1}">
and my route for the above is defined in route.js
file as:
...
{
path: 'foo/bar',
component: fooComponent()
}
...
Now, my question is how do I make my route accept a conditional url prop like /foo/bar/1
and /foo/bar
because now, it only accepts /foo/bar
Upvotes: 0
Views: 1775
Reputation: 927
If you want to make it as optional parameter, use question mark ?
.
'foo/bar/:id?'
Upvotes: 3
Reputation: 319
path: 'foo/bar/:id'
Here you can read about it: https://router.vuejs.org/en/essentials/dynamic-matching.html
Upvotes: 1