ZijianHe / koa-router

Router middleware for koa.
MIT License
4.85k stars 406 forks source link

Use longest match for ctx._matchedRoute, fixes #478 #492

Closed jcao219 closed 4 years ago

jcao219 commented 5 years ago

Fixes #478 by using the longest path, or the length of path string as a tiebreaker to determine "most specific layer"

I tried to implement it without replacing RegExp.prototype.test with something that like RegExp.prototype.exec which returns more match information, as that would decrease routing performance.

This does subtly change the behavior of koa-router, though. Is 5.x release planned soon, and will it fix #478 ?

mirague commented 5 years ago

Was running into this issue in needing to access the proper path pattern for the current route handler. Silly (useless) that it uses the first "parent" route path rather the more specific route handler.

falkenhawk commented 4 years ago

@jaco219 this repo is abandoned. Maybe you'd be interested to contribute to the active repo instead: https://github.com/koajs/router/issues/34#issuecomment-651765289

jcao219 commented 4 years ago

Let's close the issue. Feel free to merge my code into any forked repo if you feel like it.

From the time I made this PR up until now, I've moved across continents twice. I also use fastify now (as my framework of choice). I haven't thought about Koa router in 12 whole months.