Reputation: 10111
How to get the actual path of the route without params.
Getting /users/abc
expecting /users/:id
Route
router.get('/user/:id', find);
Middleware
const middleware= (ctx, next) => {
let path = ctx.path; // '/users/abc'
// Something
};
Upvotes: 1
Views: 1245
Reputation: 1200
const middleware= (ctx, next) => {
let path = ctx._matchedRoute; // '/users/:id'
// Something
};
Source code
https://github.com/alexmingoia/koa-router/blob/master/lib/router.js#L336
https://github.com/alexmingoia/koa-router/blob/master/lib/layer.js#L46
Upvotes: 3