我正在尝试构建我的第一个node.js web-app。当我尝试请求主页面(放入)时,
/home/nectarys/dev/nodejs/project/abc/server/partials/main/main.jade
我收到此错误消息,我该如何解决?
Error: Failed to lookup view "partials/[object Object]" in views
directory
"/home/nectarys/dev/nodejs/projects/abc/server/views"
at Function.app.render (/home/nectarys/dev/nodejs/projects/abc/node_modules/express/lib/application.js:508:17)
at ServerResponse.res.render (/home/nectarys/dev/nodejs/projects/abc/node_modules/express/lib/response.js:782:7)
at Object.port [as handle] (/home/nectarys/dev/nodejs/projects/abc/server.js:52:9)
at next_layer (/home/nectarys/dev/nodejs/projects/abc/node_modules/express/lib/router/route.js:103:13)
at Route.dispatch (/home/nectarys/dev/nodejs/projects/abc/node_modules/express/lib/router/route.js:107:5)
at /home/nectarys/dev/nodejs/projects/abc/node_modules/express/lib/router/index.js:213:24
at Function.proto.process_params (/home/nectarys/dev/nodejs/projects/abc/node_modules/express/lib/router/index.js:286:12)
at next (/home/nectarys/dev/nodejs/projects/abc/node_modules/express/lib/router/index.js:207:19)
at SendStream.error (/home/nectarys/dev/nodejs/projects/abc/node_modules/express/node_modules/serve-static/index.js:87:37)
at SendStream.emit (events.js:95:17) GET /partials/main/main 500 10.393 ms - 1253
路线,
app.get('/partials/*', function (req, res){
res.render('partials/' + req.params);
});
app.get('*', function (req, res){
res.render('index');
});
答案 0 :(得分:0)
您应该告诉nodejs查看第一个参数而不是对象。
更改
app.get('/partials/*', function (req, res){
res.render('partials/' + req.params);
});
到
app.get('/partials/*', function (req, res){
res.render('partials/' + req.params[0]);
});