我有3个文件 应用程式 路线/index.js 路线/home.js
app.js
var express = require('express');
var app = express();
//require routes
var index = require('./routes/index.js')
var home = require('./routes/home.js')
app.set('port',3000)
app.set('view engine', 'pug')
app.use('/', index);
app.use('/home' , home);
//app.use('/routes',users);
app.listen(3000);
module.exports = app;
index.js
var express = require('express');
var router = express.Router();
router.get('/' , function(req,res){
res.redirect('/home')
})
module.exports = router;
home.js
var express = require('express');
var router = express.Router();
router.get('/home' , function(req ,res){
res.send('Got request on home route')
})
module.exports = router;
这会在HOME路由上发送无法获取的消息。奇怪的是,如果我将两个路由都放在一个文件中,这会起作用。我认为我在导入时出错了吗?