鍍金池/ 問答/HTML/ express router.param([name] callback)為什

express router.param([name] callback)為什么name傳數組多個param不行?

const express = require('express')
const router = express.Router()
const Student = require('../students')


router.param(['id','page'], function (req, res, next, value) {
    console.log('11', value);
    next();
  })

router.get('/user/:id/:page', function (req, res, next) {
    console.log('22');
    next();
});
  
router.get('/user/:id/:page', function (req, res) {
    console.log('33');
    res.end();
});

//瀏覽器  
http://localhost:3000/user/42/2323


//控制臺結果
[nodemon] restarting due to changes...
[nodemon] starting `node app.js`
app is running at port 3000
22
33

//數組里面只有一個值,或者第一個參數直接傳一個param

const express = require('express')
const router = express.Router()
const Student = require('../students')


router.param(['id'], function (req, res, next, value) {
    console.log('11', value);
    next();
  })

router.get('/user/:id', function (req, res, next) {
    console.log('22');
    next();
});
  
router.get('/user/:id', function (req, res) {
    console.log('33');
    res.end();
});

//瀏覽器  
http://localhost:3000/user/42


//控制臺結果
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] starting `node app.js`
app is running at port 3000
11 42
22
33

不知道為什么 按官方文檔來的, 第一個參數傳數組且多個param 就進不去,求大佬們幫助下

回答
編輯回答
朕略萌

最后發(fā)現原因是 router.param 不接受多參數的, 但是express中文文檔沒人維護 API沒更新,引發(fā)的錯誤。

2017年9月11日 04:32