React路由器(使用React路由器-dom) /,/about,/contact
快速路由器/ =>呈现反应构建的index.html
为了防止“无法获得/about,/contact",我这样编码。
即使是CRA代码也与我的(https://create-react-app.dev/docs/deployment#serving-apps-with-client-side-routing)相同。
但问题是当我想直接获得"http://www.example.com/about“时,它会因为代码而重定向到"http://www.example.com/”。
我能做什么?
// rendering react
app.get("/", function (req, res) {
res.sendFile(__dirname + "/client/build/index.html");
});
// for preventing cannot get
app.use("*", (req, res) => {
res.sendFile(__dirname + "/client/build/index.html");
});
发布于 2020-06-25 09:44:16
经过和妈妈代码的斗争,我找到了机器。
你需要使用反向代理。
我用的是Nginx。
https://stackoverflow.com/questions/62448860
复制相似问题