我正在尝试通过从 mongodb 数据库获取页面,使用express在nodejs中动态创建路由。
我在routes.js
中的代码类似于:
module.exports = function(app, passport) {
Page.find(function(err,leroutedata){
leroutedata.forEach(function(page) {
var path = page.path;
app.get(path,function(req, res){
res.render('layout.ejs', { data : page });
});
});
});
};
但我收到此错误:
(...)/node_modules/path-to-regexp/index.js:34
.concat(strict ? '' : '/?')
^
TypeError: Cannot read property 'concat' of undefined
知道是什么原因造成的吗?
最佳答案
您的page.path
可能不是字符串或正则表达式
关于javascript - Express 中的动态路由, "Cannot read property ' concat' of undefined”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34353877/