-
Notifications
You must be signed in to change notification settings - Fork 407
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
Nested routers behaviour changed in koa@7 #369
Comments
@pmrukot does this solve your issue?
On the main router, in order to remove the undesired (.*) |
jbielick
added a commit
that referenced
this issue
Jan 20, 2018
fixes what looks like a regression in 8665620 in which `path` inside of `.use()` is defaulted to a wildcard `(.*)` instead of remaining undefined while the line: if (path) nestedLayer.setPrefix(path) runs. https://github.com/alexmingoia/koa-router/blob/840591d4f660ddde98aedc689dea862a7e63f55b/lib/router.js#L265 This fixes #369 and #410 A test case has been added.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi 👋
I've encountered an issue while migrating to koa@2 with koa-router@7. Im nesting my routes like these:
And I've noticed that the paths in my routes changed, to be specific
(.*)
was added to them. So the paths looked like below:Before (koa@5):
/firstPrefix/secondPrefix
After (koa@7):
/firstPrefix(.*)/secondPrefix(.*)
And my routes broke as you may guess. (needed to add additional dummy string to match syntax)
So I went to the sources:
koa-router@5:
https://github.com/alexmingoia/koa-router/blob/5.x/lib/router.js#L221
https://github.com/alexmingoia/koa-router/blob/5.x/lib/router.js#L258
koa-router@7:
https://github.com/alexmingoia/koa-router/blob/master/lib/router.js#L246
https://github.com/alexmingoia/koa-router/blob/master/lib/router.js#L276
In koa-router@5 there is:
while in koa-router@7:
The problem is, that in koa-router@7 path is always truthy, and the prefix of
(.*)
is being set while no string is specified in first argument:https://github.com/alexmingoia/koa-router/blob/master/lib/router.js#L257
https://github.com/alexmingoia/koa-router/blob/master/lib/router.js#L265
I've also found some relevant issues here:
#155
Similar to mine, I've changed the routes declaration to:
And now it seems to work as before. But the discussion in the issue above was just cut, with no explanation or followup if this is a bug or not.
I've also found these ones that may be relevant:
8665620
#260
So the question: is this intentional behaviour? I haven't found anything in docs about this change.
The text was updated successfully, but these errors were encountered: