gpt4 book ai didi

node.js - 使用 Pushstate 和 NodeJS

转载 作者:太空宇宙 更新时间:2023-11-04 01:13:00 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com