Next.js Discord

Discord Forum

Dynamic routes questions

Answered
Palomino posted this in #help-forum
Open in Discord
Avatar
PalominoOP
I have worked with nextjs for a few months now, and the dynamic routes [param] is great and all, but they seem to catch all requests that isnt defined.

example: dynamic route on .tld/[filename]; and then if I get a GET request on that route which isnt defined ( like wpad.dat. it gets sent to that route. is there any way to match routes, so that only a certain format is sent to that dynamic route, I know I can add checks inside the route itself but that means the request is caught after all? like how middleware.js/ts has a matcher thing.
sorry if this is a obvious thing, I have looked in docs but havent had luck ( I am able to read 3 out of 7 times )
Answered by joulev
if your dynamic route has generateStaticParams, can use [the dynamicParamsexport](https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams)

if not, then yea if (...) notFound() is pretty much the only way, there isn't a matcher for the dynamic route
View full answer

2 Replies