dynamic路由expression式中,“不能读取未定义”错误的属性“concat”

我试图通过从mongodb数据库中获取页面来使用express来在nodejs中dynamic创build路由。

我在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 

任何ideea什么可以导致它?

你的page.path可能不是一个string或正则expression式