错误:找不到带有/:id的模块'html'

Max*_*kel 2 routes node.js express

我最近在渲染html页面时遇到了快速问题.我的应用程序有以下组织:

app/ server.js views/ index.html dashboard.html containers/ show.html ......

在server.js中,我声明了以下路由:

app.configure(function(){
   app.use(express.static(path.join(__dirname,'/views')));
});

app.get('/containers/:id',function(req,res){
   console.log("Inspect container");
   res.render('/views/containers/show.html');
});
Run Code Online (Sandbox Code Playgroud)

在dashboard.html中,我有一个如下所示的链接:

<a href="/containers/'+data[i].Id+'">Test</a>
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试访问以下链接时,我收到此错误:

Error: Cannot find module 'html' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) at require (module.js:380:17) at new View (/root/HarborJS/node_modules/express/lib/view.js:43:49) at Function.app.render (/root/HarborJS/node_modules/express/lib/application.js:488:12) at ServerResponse.res.render (/root/HarborJS/node_modules/express/lib/response.js:759:7) at io.sockets.on.socket.on.exec.user (/root/HarborJS/server.js:32:7) at callbacks (/root/HarborJS/node_modules/express/lib/router/index.js:164:37) at param (/root/HarborJS/node_modules/express/lib/router/index.js:138:11)

我真的不知道该做什么.告诉我,如果我做错了什么.

log*_*yth 6

res.render用于为每个请求动态生成页面HTML服务器端.您已将其传递给HTML文件的路径,但HTML不是模板语言,因此它会抛出错误.

如果你没有任何模板逻辑,show.html那么你应该在不使用模板引擎的情况下发回文件,例如

res.sendfile(__dirname + '/views/containers/show.html');
Run Code Online (Sandbox Code Playgroud)

如果确实有需要在服务器端呈现的东西,那么你应该选择一个模板引擎,其中有很多,然后重命名文件以具有模板扩展名.