我正在使用 NodeJS 和 HTML5 Pushstate。 我的index.html位于“/”,其中包含通过pushstate转到“/home/”的链接。一切都很好,但是如果我刷新/home/上的页面,我的服务器将返回“无法获取/home/”。
我只想“/home/”像“/”一样返回我的index.html文件
我的代码:
var express = require("express"),
app = express();
app.use(express.static(__dirname + '/public'));
app.get('/home/', function(req, res, next) {
//what to do here?
});
app.listen(3001);
谢谢。
最佳答案
将/
放在/home
之后:
app.get('/home', function(req, res, next) {
关于在这里做什么
,您可以收集所需的数据,并返回响应。例如: res.end("Hello world!");
如果您希望在 /home
处提供静态文件,则:
app.use("/home", express.static(__dirname + "/public"));
关于node.js - 使用 Pushstate 和 NodeJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14540243/