【发布时间】:2018-01-21 12:51:59
【问题描述】:
我正在制作一个网站,对于前端,我使用的是 HTML。对于后端,我使用的是 node/Express。
在 HTML 中,我有一些用于重定向不同 HTML 页面的锚标记。为了创建不同的路由,我在 Express 中使用了路由器。
现在的问题是当我通过节点运行我的网站时,重定向没有按预期工作。
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;
当我通过节点运行网站并输入:
localhost:3000/发布
然后我得到publication.html,当我输入时
本地主机:3000
它打开 index.html 并且在我的索引页面中,我有上面的锚标记。 现在,如果我单击任何锚标记,则会收到一条错误消息,例如“无法获取publication.html”,我想要重定向到我的publication.js 并调用
router.get('/publication')
方法然后打开publication.html
谁能指出我正确的方向?
【问题讨论】:
标签: html node.js express anchor