-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Colliding routes causes params to be undefined in route handler #149
Comments
It seems related to fastify/fastify#2261 |
The solution is to:
|
This does not solve the problem. If you request So while you, in this specific case, can infer that
If someone requests |
If you are using |
You can also set a default for the color param with configuring a schema for the params: https://www.fastify.io/docs/latest/Validation-and-Serialization/#validation. |
This issue was fixed. I added a test here #262. We can close this. |
Hi!
I was working on a project and I found some odd behaviour while using Fastify. I managed to reproduce it in
find-my-way
, so here goes.Given the following routes, each with their own handler:
GET /foo/:id
(handler 1)GET /foo/:color/:id
(handler 2)GET /foo/red
(handler3)If you then do a
GET /foo/red/123
, the correct handler (handler 2) will be invoked.The
id
-param will correctly be'123'
, but thecolor
param is undefined.If you do a
GET /foo/blue/123
, both params are correct (blue
,123
).Handler 3 is still correctly invoked for
GET /foo/red
. So the routing is correct, but the params are wrong.If you unregister
GET /foo/red
the/foo/:color/:id
route will then work again withred
.I created a fork of the repo with a unit test to illustrate the problem: ajaco@8b48949
That test will fail with the following output:
So I'm not sure if this is a bug or intended, but I found it very odd. Hopefully this issue will either highlight a bug, or make me understand this behaviour.
The text was updated successfully, but these errors were encountered: