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:

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

but, it’s probably best to do it on the component level. Like so:

Note the optional flag on the param: :id?. More info here:

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.