pedronauck / micro-router

:station: A tiny and functional router for Zeit's Micro

Home Page:https://www.npmjs.com/microrouter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trouble with matching routes

adamgruber opened this issue · comments

I've come across an issue where my requests are not getting handled as I would expect. In my code I've got something like this:

module.exports = router(
  get('/users/:id', usersHandler),
  get('/users/:id/resource', resourceHandler)
);

When I make a GET request to /users/12345/resource, the usersHandler is being called, not the resourceHandler. I believe this is happening because the request matches both paths but how can ensure that my request is handled by the correct handler?

I can confirm this as well. As a work around, place the more complicated path above the simpler one (i.e. switch the order).

When I switch routes, both routes get called. Applying the the change made by Roman's PR, fixes the issue.