这是我的路线:
router.route('/search:word').get(function(req, res) {
var re = new RegExp(req.params.word, 'i');
console.log(req.params.word);
Place.find().or([{ 'title': { $regex: re }}, { 'category': { $regex: re }}]).sort('title').exec(function(err, places) {
res.json(JSON.stringify(places));
});
});
当我使用请求 /places/search:test
时,控制台显示 :test 而不仅仅是“test”。
知道发生了什么吗?
最佳答案
您真的要使用 router.route('/search:word')
而不是 router.route('/search/:word')
吗?使用冒号似乎有点奇怪。
如果您使用router.route('/search/:word')
,并且如果您的请求是
/places/search/test
然后你得到 req.params.word="test"
关于node.js - 我使用 express for node.js 得到冒号和我的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23576284/