【发布时间】:2012-04-03 20:24:59
【问题描述】:
我在 expressjs 的单独文件夹中有路由。该设置在“索引”页面上运行良好,但不适用于任何其他路线。
这是我的 index.js,在我的路由文件夹中。
module.exports = function(db) {
return {
index: function(req, res, next) {
res.send('index');
}
}
}
这是我的 join.js,在我的路由文件夹中。
module.exports = function(db) {
return {
join: function(req, res, next) {
res.send('join');
}
}
}
在我的 app.js 中,我这样定义路由:
var routes = require('./routes')(db);
app.get('/', routes.index);
app.get('/join', routes.join);
当我转到http://localhost:3000 但当我转到http://localhost:3000/join 时,我得到Cannot GET /join
如果我这样定义我的加入路线:
app.get('/join', function(req, res){
res.send('join 2');
});
这行得通。
知道我在这里做错了什么吗?
谢谢!
【问题讨论】:
标签: javascript node.js express