节点/快速锚链路线

我正在做一个网站和前端,我正在使用HTML。 对于后端,我正在使用节点/ Express。

在HTML中,我有一些redirect不同HTML页面的锚定标记。 为了创build不同的路线,我在Express中使用了Router。

现在的问题是,当我通过节点运行我的网站,然后redirect不能按预期工作。

index.html的:

<li><a href="index.html">Home</a></li> <li><a href="publication.html">Publication</a></li> <li><a href="team.htm">Team</a></li> <li><a href="contact.html">Contact</a></li> 

ExpressJS:

index.js:

  var express = require('express'); var path = require('path'); //router object var router = express.Router(); router.get('/', function (req, res) { res.sendFile(path.join(__dirname, '..', '/public/html/index.html')); }); module.exports = router; 

publication.js:

  var express = require('express'); var path = require('path'); //router object var router = express.Router(); router.get('/publication', function(req, res){ res.sendFile(path.join(__dirname, '..', '/public/html/publication.html')); }); module.exports = router; 

当我通过节点运行网站并input:

本地主机:3000 /出版物

那么我得到的publication.html,当我键入

本地主机:3000

它打开index.html,并在我的索引页面,我有上面的锚标签。 现在,如果我点击我的任何一个锚标签,然后我收到一个错误消息,如“无法得到publication.html”我想要的是redirect到我的publication.js和调用

 router.get('/publication') 

方法,然后打开publication.html

任何人都可以指出我正确的方向?

这个代码

  <li><a href="index.html">Home</a></li> <li><a href="publication.html">Publication</a></li> <li><a href="team.htm">Team</a></li> <li><a href="contact.html">Contact</a></li> 

会生成如http:// localhost:3000 / index.html的链接。 现在你后端不知道这个路由,因为你定义了你的路由/publication等等。 你必须修改它像下面的东西

  <li><a href="/">Home</a></li> <li><a href="publication">Publication</a></li> <li><a href="team">Team</a></li> <li><a href="contact">Contact</a></li> 

更多关于快速路由