search

Home  >  Q&A  >  body text

koa-router cannot get path parameters - Stack Overflow

Environment
Node 8.0.0
koa 2.2.0
koa-router 7.1.1

const router = require('koa-router')()

router.prefix('/logs/mobile')

router.get('/:platform', function(cxt, next) {
    console.log('params', this.params);
    cxt.body = { error: 'test'}
})

module.exports = router

The code is as shown above, and then access http://127.0.0.1:9901/logs/mobile/ios and successfully obtain the return value of the body,
but this.paramsisundefined

天蓬老师天蓬老师2784 days ago679

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-06-15 09:24:49

    You need to use ctx.params

    reply
    0
  • Cancelreply