You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
letusersRouter=newRouter().use(async(ctx,next)=>{console.log(ctx.params.userId??'No user ID in params')returnnext()}).get('/',async(ctx,next)=>{ctx.body={id: 1,name: 'John Doe'}})exportletrouter=newRouter().use('/users/:userId',usersRouter.routes(),usersRouter.allowedMethods())
Expected Behavior:
The middleware prints userId to console.
Actual Behavior:
The middleware prints 'No user ID in params' because ctx.params.userId is undefined.
Additional steps, HTTP request details, or to reproduce the behavior or a test case:
This is actually fixed by calling .use() with an empty path 🤷♂
letusersRouter=newRouter()// Here an empty path is used. Previosly it was omitted..use('',async(ctx,next)=>{console.log(ctx.params.userId??'No user ID in params')returnnext()}).get('/',async(ctx,next)=>{ctx.body={id: 1,name: 'John Doe'}})exportletrouter=newRouter().use('/users/:userId',usersRouter.routes(),usersRouter.allowedMethods())
The text was updated successfully, but these errors were encountered:
node.js
version:16.2.0
yarn
version:1.22.10
@koa/router
version:10.0.0
koa
version:2.13.1
Code sample:
Expected Behavior:
The middleware prints
userId
to console.Actual Behavior:
The middleware prints 'No user ID in params' because
ctx.params.userId
is undefined.Additional steps, HTTP request details, or to reproduce the behavior or a test case:
This is actually fixed by calling
.use()
with an empty path 🤷♂The text was updated successfully, but these errors were encountered: