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

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 accesshttp://127.0.0.1:9901/logs/mobile/iosand successfully obtain the return value of the body,
butthis.paramsisundefined

天蓬老师
天蓬老师

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

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

You need to usectx.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!