recherche

Maison  >  Questions et réponses  >  le corps du texte

express 路由无法访问二级目录

1、问题描述:初学express,首次配置,发现路由无法设置访问到views的二级目录。

2、代码:index.js

var express = require('express');var router = express.Router();
var title = 'xxxxx';/* GET home page. */router.get('/', function(req, res, next) {
    res.render('index', { title: title});
});

router.get('/dna', function(req, res, next) {
    res.render('pages/dna', { title: title});
});module.exports = router;

app.js

var routes = require('./routes/index');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');


app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// app.use(express.static(path.join(__dirname, 'views')));

app.use('/', routes);

3、报错信息

GET /dna 500 476.011 ms - 1214
Error: Failed to lookup view "error" in views directory "xxxxxxx"                                                                                                                                                                                                                       
    at EventEmitter.render (xxxxxxxxxxxxx\node_modules\express\lib\application.js:579:17)                                                                                                                                                                                                           
    at ServerResponse.render (xxxxxxxxxxxxxxxxxxxxxxxx:961:7)                                                                                                                                                                                                             
    at xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\app.js:52:7

4、目录结构

985736400-582c660086cf8_articlex.png

高洛峰高洛峰2934 Il y a quelques jours658

répondre à tous(1)je répondrai

  • 三叔

    三叔2016-11-17 15:47:44

    这个不是找不到的问题,是你views目录里边要有一个error.jade的视图文件

    répondre
    0
  • Annulerrépondre