T
TanStack2w ago
exotic-emerald

Matching `/info/` and /info/something/$slug` but not `/info/something`

Is it possible to create something like this with just one route?
4 Replies
eager-peach
eager-peach2w ago
No.
correct-apricot
correct-apricot2w ago
I mean, you can make a match for this, but it would just be
/info/$slug
/info/$slug
Personally, I would just make three routes
info/
index.ts
something.ts
something.$.ts
info/
index.ts
something.ts
something.$.ts
If all of these share a layout, you can make a route.ts in the info folder to have a shared layout, and if something/$slug is not a child of something, then you need to make sure that the file is named something_.$.ts so that something is not a parent route Actually sorry, I mis-read your question, you don't want /info/something I think you can just do
info/
index.ts
something_.$.ts
info/
index.ts
something_.$.ts
underscore before the . signifies that it should act as one match. You will still require two routes though. It probably helps if you can indicate what you expect the behaviour to be? is /info/ completely unrelated to /info/something/$slug or does it act as a layout. you will require two routes either way (but the structure you use would change based on the requirements)
exotic-emerald
exotic-emeraldOP2w ago
Yes, I'd like to have something like this /blog (shows all categories) /blog/categories/$slug shows posts per category /blog/$slug shows specific blog post UI in both blog and blog/categories/how-to would be exactly the same we would just mark tab how-to as active I know I can create 2 routes and extract whole content to a separate component however thought there is away
correct-apricot
correct-apricot2w ago
Personal I think 3 at minimum will make your life easier in the long run
blog/
route.ts
categories_.$category # will not match `/blog/category`
blog_.$post
blog/
route.ts
categories_.$category # will not match `/blog/category`
blog_.$post

Did you find this page helpful?