Reputation: 1747
I have the following router.js with few dozens of value-x, i.e. value-one, value-2.
const router = new Router({
routes: [
{
path: "/plant/value-one",
name: "value-one",
components: {
default: Site
},
props: {
default: {
tab: 'value-one',
menu: 'value-one'
}
}
},
{
path: "/plant/value-two",
name: "value-two",
components: {
default: Site
},
props: {
default: {
tab: 'value-two',
menu: 'value-two'
}
}
}
]
}
)
I would like to turn it into something like this:
path: "/plant/*"
I tried the following:
const router = new Router({
routes: [
{
path: "/plant/{:name}",
name: name,
components: {
default: Site
},
props: {
default: {
tab: name,
menu: name
}
}
}
]
}
)
Name variable should also be passed to route's name as well as to tab and menu variables.
What am I missing here?
Upvotes: 1
Views: 1880
Reputation: 347
I suggest to use children routes like this:
{
path: '/plant',
component: plantComponent,
children: [
{
path: ':name',
component: someComponent,
name: 'someName'
},
]
}
now any route after the plant/ can be defined as children of routes and i have defined a route :name
which will be used for plant/*
If you don't want to use children routes and just concerned with passing route parameters, use the parameter without the braces :
path: "/plant/:name",
Upvotes: 1