[英]Express.js request params undefined
I've got the following node/express code: 我有以下节点/表达代码:
app.get("/notes/:categoryName", function (res, req) {
var categoryName = req.params.categoryName;
res.render("notes", {title: categoryName});
});
But when I look at req.params, it's undefined. 但是当我查看req.params时,它是不确定的。
Yet, in another controller it works fine: 但是,在另一个控制器中它可以正常工作:
app.get("/api/notes/:categoryName", function (req, res) {
var categoryName = req.params.categoryName;
data.getNotes(categoryName, function (err, notes) {
if (err) {
res.send(400, err);
} else {
res.set("Content-Type", "application/json");
res.send(notes.notes);
}
});
});
What's the deal? 这是怎么回事?
app.get("/notes/:categoryName", function (res, req) {
More attention : 更多关注:
app.get("/notes/:categoryName", function (req, res) {
You switched the params (res, req) 您已切换参数(res,req)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.