Echo JS 0.11.0

<~>
hideula 3248 days ago.
Hi, this is my first routing (micro)library - https://github.com/eugene-eeo/troute.js. Hah, trout, get it? Anyways, what I want to know is if in practice, backtracking is of any use - that is, matching /user/1 against

  /user/:id
  /user/1/:photo_id

Will return the first route instead of the second one. I sometimes find myself needing to write routes which require backtracking.

From my research, most router libraries out there use a list of regexes and matching against them. I am not sure if this is very performant especially when many routes are added, so I used a tree data-structure instead.

Lastly, I will be extremely grateful for any help or PRs.

Citrus 3247 days ago. link 2 points
Much of the time, I've found that we want the more-specified routes to match first, leaving the more generally specified routes to only match if there isn't one more specifically specified.

In other words, no matter where the route is registered, the second route should always match if it can, and the first should only route if the second can't.

As for your initial question, I would say that you could go either way, as long as the library is consistent about the behavior, and that behavior is clearly documented up front.  That said, what you're suggesting makes sense.  Just make sure your documentation is very clear that that is the effect.

"Explicit is better than implicit."  At least when it comes to routing...