javascript - Express 中的动态路由, "Cannot read property ' concat' of undefined”错误

标签 javascript node.js mongodb express

我正在尝试通过从 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/

相关文章:

javascript - Angular JS 不反射(reflect) Controller $scope 对象的变化

javascript - Angular js : using html elements within ternary operators

javascript - AJAX 未将图像上传到后端服务

javascript - MongoDB - 获取从开始日期到结束日期的数据

mongodb - 如何快速查找数组中至少有一个元素的所有 mongo 文档

javascript - jQuery 显示/隐藏栏取决于 css 类

node.js - 使用 Node db-migrate 在事务中禁用包装迁移

javascript - Node.js 延迟 Promisify + mongoose

python - 导出时使用大JSON会导致内存问题

javascript - 将 jqWidgets 组合框限制为值列表