javascript - Express js 4x :req.params returns empty object -
trying url parameters in express js,but got empty object.
var password= require('./routes/password'); app.use('/reset/:token',password);
password.js
router.get('/', function(req, res, next) { console.log(req.params); res.send(req.params); });
console.log(req.params)
output {}
access url :http://localhost:3000/reset/civv6u9huples3i0eusnwk9zb7xvzpfhsqnuzmnwqllga4njkoagwbcyiuz8
by default, nested routers not passed parameters used in mountpaths parent routers.
in case, app
parent router, uses /reset/:token
mountpath, , router
nested router.
if want router
able access req.params.token
, create follows:
let router = express.router({ mergeparams : true });
documented here.
Comments
Post a Comment