fiber: Problem with Route path
Fiber version 1.12.6
Issue description Nested Route paths not invoking the correct handler.
Code snippet
func SetupRoutes(app *fiber.App) {
todo := app.Group("/todo", middleware.Logger())
todo.Get("/:id", handler.ReadTodo)
todo.Post("/", handler.CreateTodo)
todo.Put("/:id", handler.UpdateTodo)
todo.Delete("/:id", handler.DeleteTodo)
todo.Get("/all/todos", handler.ReadAllTodo)
todo.Get("/all", handler.DummyAllHandler) // this does not working, it always invoking todo.Get("/:id", handler.ReadTodo)
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (9 by maintainers)
The presented case above would have the same results in Expressjs,
/:id
also matches/all
. @kiyonlin explained this perfectly, just like in Express: order matters πThanks for your reporting! But I donβt it is counted as a bug.
According to your example, there are two approaches to solve the problem:
You can place routes in the appropriate order so that
Fiber
can do the right thing πHi @mohanasundaramn
When you put
/:id
above/all
, you should do theNext
thing. But your first example just do the opposite.Btw @mohanasundaramn
That is because
Fiber
always finds the first route to match the requestβs path and breaks the route chain if there is no moreNext
is called.It is probably taking your path βallβ as the id parameter. Being in the same method I assume that you must be taking it this way id = βallβ. Try putting using StrictRouting.
app := fiber.New(&fiber.Settings{ StrictRouting: true, })
Nope, as I said above.
I adjusted your code:
@solrac97gr
setting
StrictRouting: true
does not fix the problem still invokingtodo.Get("/:id", handler.ReadTodo)