【发布时间】:2015-11-22 07:54:21
【问题描述】:
我正在为我的网站使用 node.js 和 express。当用户单击 index.html 中的链接时,我需要能够引导用户。 我有三个页面:index.html、presentation.html、join.html 都在公共文件夹中。 这就是我在 server.js 中进行路由的方式:
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.bodyParser({ keepExtensions: true, uploadDir: __dirname + '/_tmp'}));
这就是我在 index.html 中编写链接的方式:
<a class="btn" href="/presentation">Presentation</a>
<a class="btn" href="/join">Join</a>
当我运行服务器时,我得到了 index.html,但是当我单击其中一个链接导航到其他页面时,我得到了这个错误:
Cannot GET /presentation
当我尝试添加到 server.js 时:
app.get('/presentation',function(req,res){
res.render('public/presentation.html' , { root : __dirname});
});
我收到此错误:
TypeError: undefined is not a function
这是我的应用布局:
App
/pulic
indx.html
join.html
presentatio.html
server.js
如何启用导航?
【问题讨论】: