首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动态路由中的“无法读取属性'concat‘的未定义”错误

动态路由中的“无法读取属性'concat‘的未定义”错误
EN

Stack Overflow用户
提问于 2015-12-18 10:50:22
回答 1查看 731关注 0票数 1

我试图通过从mongodb数据库获取页面,使用express动态创建nodejs中的路由。

我在routes.js中的代码类似于:

代码语言:javascript
复制
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 });
            });
        });
     });
};

但我知道这个错误:

代码语言:javascript
复制
(...)/node_modules/path-to-regexp/index.js:34
    .concat(strict ? '' : '/?')
    ^

TypeError: Cannot read property 'concat' of undefined

有什么会导致的吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-18 10:52:23

您的page.path可能不是字符串或Regex。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34353877

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档