Open zhuscat opened 7 years ago
after init router
router.stack.forEach(routerItem => routerItem.stack.unshift(mw))
Does a cleaner way to do this exist?
@zhuscat
const router = new Router({
prefix: "/users/:id",
})
// GET /users/123
router.use("*", async (ctx, next) => {
// ctx.params = {id: "123"}
await next()
})
I have a middleware(let's call it
mw
) which will use ctx.params to get the parameter in a path.If I write:
The
ctx.params
in themw
is{}
But if I write:
The
ctx.params
in themw
is{ id: 'some_id' }
I want my middleware to be called for every route and I want to get the right
ctx.params
.Is there any way to solve this problem?