-
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
The ctx. _matchedRoute is not the route I requested! #516
Comments
I have found something that may help. node_modules\koa-router\lib\router.js
As shown in the code, ctx._matcheRoute is the most matched route path insteadof requested. |
Fixes ZijianHe#516 To not break backwardscompatibility, i'd not "fix" the `_matchedRoute` but introduce `ctx.routerPath` analog to `ctx.routerName`
I ran into the same problem. The issue is, that matchedLayers contains - as the name suggests - all matched layers, that will be put in the middleware-chain (because the regex matches). In the case above, it's because With that being said, the I've created PR #524, which would populate |
@schwarmco this is the official one from koa org https://github.com/koajs/router , a fork of this repo |
@tuananh thanks - i opened a pull-request there... just landed here, because i searched for this exact same issue :) |
Thanks very much, I have some things I did not pay attention to this issue in time, sorry! |
Already got help:https://github.com/koajs/router/releases/tag/v9.1.0 Thx!!!!! |
node.js version: 12.12.0
npm/yarn and version: 6.11.3
koa-router
version: 7.4.0koa
version: 2.10.0hi,I have some problems. I use koa tag 2.7.0 .
Now I have two routes, one is "/api/order/list" and another is "/api/order/:orderId" .
I want to log each request. When I request the second interface with params, I want the url I am recording to be the url of my own defined api, not the url directly with params.For example, when I request "http://127.0.0.1:3000/api/order/57d52c52403f2ee865738ec7", I want to record that the url is "/api/order/:orderId" instead of "/api/order/57d52c52403f2ee865738ec7".
But ctx.url ctx. originalUrl is not what I want, and ctx. _matchedRoute is what I want.However, I have a new problem. When I request "/api/order/list", the value of ctx._matchedRoute is still "apr/order/:orderId" instead of "/api/order/list" and ctx.matched is an array of two object elements.
Why the _matchedRoute is not the route I requested?
Code sample:
http:127.0.0.1:3000/api/order/list
http:127.0.0.1:3000/api/order/:orderId
The text was updated successfully, but these errors were encountered: