如何获取不带参数的路线的实际路径。
得到/users/abc
期望/users/:id
路线
router.get('/user/:id', find);
中间件
const middleware= (ctx, next) => {
let path = ctx.path; // '/users/abc'
// Something
};
答案 0 :(得分:0)
const middleware= (ctx, next) => {
let path = ctx._matchedRoute; // '/users/abc'
// Something
};
源代码
https://github.com/alexmingoia/koa-router/blob/master/lib/router.js#L336
https://github.com/alexmingoia/koa-router/blob/master/lib/layer.js#L46