无法弄清楚如何在快递中呈现新页面

时间:2015-01-24 07:17:42

标签: javascript express routes

我的路线文件夹中有ships.js

var express = require('express');
var router = express.Router();

/* GET Ships page. */
router.get('/ships', function(req, res, next) {
  res.render('ships', { title: 'Express' });
});

module.exports = router;

我在app.js

中有这些陈述
var routes = require('./routes/index');
var users = require('./routes/users');
var ships = require('./routes/users');

app.use('/', routes);
app.use('/ships', ships);
app.use('/users', users);

但是,如果我导航到localhost:3000/ships,我会收到以下消息:

以资源回复

很抱歉已阅读过这些文档,只是不要用快递来表达。

1 个答案:

答案 0 :(得分:0)

app模块中有两个错误:

1. require路由无效ships

var ships = require('./routes/users'); <--
// should be:
var ships = require('./routes/ships');

2. router使用无效app.use

app.use('/ships', ships);
// should be:
app.use(ships); // and the same for others