Can you create a route parameter with a default value?

I need to access a dynamic route with parameters but in case the parameter is not sent dynamically, assign a default value
I have this path: ‘my-path /: param’
I would like to assign a default value to: param for example zero

On the route level you can using a function. Like so: https://jsfiddle.net/jamesbrndwgn/cd4oshjx/

{ path: '/user/:id?', component: User, props: (route) => ({ id: route.params.id || 'default' }) }

but, it’s probably best to do it on the component level. Like so: https://jsfiddle.net/jamesbrndwgn/4m7t0szq/

Note the optional flag on the param: :id?. More info here: https://router.vuejs.org/guide/essentials/dynamic-matching.html#advanced-matching-patterns

I tried this , but inside my component when I log $route , $route.params .id is undefined

I was looking for something similar to this, and using $route.meta instead of $route.params worked well for me.

Vue documentation discusses this here.

Basically, you just add a meta object to your route, for example…

meta: { requiresAuth: true }

… then you can reference it in Vue with $route.meta.requiresAuth when you go to that route.