Is it possible to generate a URL route with 2 variables at the same level?
Answered
jpaask posted this in #help-forum
jpaaskOP
Doubt about route creation.
I want to create the following url:
But I can't find how to do it.
I am not looking for this:
I have thought about using a
I want to create the following url:
/best-[category]-of-[monthName]But I can't find how to do it.
I am not looking for this:
/best/[category]/of/[monthName]I have thought about using a
/[slug] and create a kind of "route-checker" that reads the slug and detecting composition it shows me one thing or another but I find it very unusable
Answered by American Crow
Can't do it out of the box with with just folder structure.
As you mentioned you'd have to do a
As you mentioned you'd have to do a
/[slug] and something likeconst dynamicParams = false
export function generateStaticParams() {
const categories = ['love','hate','crime']
const monthNames = ['jan', 'feb', 'march']
// some logic to combine them
// ...
const categoriesMonths = [
{
category: 'love'
month: 'jan'
},
...
]
return categoriesAndMonths.map(({category,month}) => ({
slug: `best-${category}-${month}`,
}))
}2 Replies
American Crow
Can't do it out of the box with with just folder structure.
As you mentioned you'd have to do a
As you mentioned you'd have to do a
/[slug] and something likeconst dynamicParams = false
export function generateStaticParams() {
const categories = ['love','hate','crime']
const monthNames = ['jan', 'feb', 'march']
// some logic to combine them
// ...
const categoriesMonths = [
{
category: 'love'
month: 'jan'
},
...
]
return categoriesAndMonths.map(({category,month}) => ({
slug: `best-${category}-${month}`,
}))
}Answer
jpaaskOP
Thanks @American Crow