The ctx. _matchedRoute is not the match route.
See original GitHub issuenode.js version: v13.0.1
npm/yarn and version: 6.12.0
koa-router
version: 7.4.0 and i tried @koa/router v8.0.2, too.
koa
version: 2.7.0
Code sample:
Now I have two routes, one is “/api/order/list” and another is “/api/order/:orderId” ,
const Router = require("koa-router");
const router = new Router({
"prefix": "/api",
});
router.get('/order/list',controller.getOrderList);
router.get('/order/:orderId',controller.getOrder);
I want to log each request.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”,And when I request “http://127.0.0.1:3000/api/order/list”, I want to record that the url is “/api/order/list” instead of “/api/order/:orderId”. But ctx. _matchedRoute is not the route I requested.
Expected Behavior:
when I request “http://127.0.0.1:3000/api/order/list”, ctx. _matchedRoute is “/api/order/:orderId”
Actual Behavior:
ctx. _matchedRoute is “/api/order/list”
Additional steps, HTTP request details, or to reproduce the behavior or a test case:
i have the four screenshots.
http:127.0.0.1:3000/api/order/list
ctx.matched
http:127.0.0.1:3000/api/order/:orderId
ctx.matched
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (7 by maintainers)
Top GitHub Comments
@koa/router
v9.1.0 released to npm and mirrored tokoa-router
as wellhttps://github.com/koajs/router/releases/tag/v9.1.0
@niftylettuce I transferred this PR from the original repo and this fix solves this problem. Works great on my project 😃