Reputation: 1158
I've grubbed a couple of lines from express docs to understand how it works:
// ./routes/test.js
var router = require('express').Router();
router.param(['id', 'page'], function (req, res, next, value) {
console.log('CALLED ONLY ONCE with', value);
next();
});
router.get('/user/:id/:page', function (req, res, next) {
console.log('although this matches');
next();
});
router.get('/user/:id/:page', function (req, res) {
console.log('and this matches too');
res.end();
});
module.exports = router;
and mounted them in the usual way: app.use('/test', require('./routes/test'));
The problem is that the callback passed in .param
doesn't get executed. When I change the first line to var router = require('express')();
it works fine. An app is just a Router with some additional stuff.
I use express 4.12.4
. Any ideas?
Upvotes: 0
Views: 563
Reputation: 1158
Well, it's not a bug. It's a bug, but in the docs. A Router doesn't accept an array as the first arg, an app does.
Upvotes: 1