Next.js Discord

Discord Forum

Something like Regex for Dynamic Routes?

Unanswered
Croatian Sheepdog posted this in #help-forum
Open in Discord
Croatian SheepdogOP
Hi all!

I'm starting on the Next.js ecosystem and I have encountered that the router based on the folder directories is too basic for some cases or I haven't understood something well.

I have the following paths that should route to the same page.tsx file:
/politics/this-is-the-slug.html
/nation/this-is-the-slug.html
/world/this-is-the-slug.html

On other frameworks I define these routes with something like this: (politics|nation|world)(:slug).html

But with Next, if I define a folder structure like this:
- app
- [category]
- [slug]

How can I limit the category param to these 3 possible values?
And on the other hand, how can I restrict that the slug ends with .html?

Thanks!

0 Replies