찾다

 >  Q&A  >  본문

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

高洛峰高洛峰2936일 전666

모든 응답(1)나는 대답할 것이다

  • 三叔

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

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

    회신하다
    0
  • 취소회신하다