koa-router cannot get path parameters - Stack Overflow
天蓬老师
天蓬老师 2017-06-15 09:22:49
0
1
641

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

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
我想大声告诉你

You need to use ctx.params

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!