首页 > node 中 get怎么写传参函数

node 中 get怎么写传参函数

node 中 get怎么写传参函数
http://demo.com/todos/id/56fbc659ebcb7d00519d6967
列出这个id下的数据
要实现这样的url函数要怎么写

//这样是指向http://demo.com/todos/
router.get('/', function(req, res, next) {
        
});

看样子你用的可能是express,那你怎么着也应该这么写:

修正,经@e10101 提示,你的根路径就是/todos,那么我的答案就要改了。答案一致

router.get('/id/:id', function(req, res, next) {
    var id = req.params.id;
    console.log('This is your ID: ', id);
});

看文档:params


router.get('/id/:id', function(req, res, next) {
    var id = req.params.id;
    console.log(id);
});
【热门文章】
【热门文章】