Dynamic routes questions
Answered
Palomino posted this in #help-forum
PalominoOP
I have worked with nextjs for a few months now, and the dynamic routes
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 )
[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
if not, then yea
generateStaticParams
, can use [the dynamicParams
export](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 route2 Replies
@Palomino 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 )
if your dynamic route has
if not, then yea
generateStaticParams
, can use [the dynamicParams
export](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 routeAnswer
PalominoOP
alright. I mean, thats probs most logical either way