我有一个使用以下内容作为路由器历史记录的react应用。
import { BrowserRouter, Route, Link } from "react-router-dom";
import { createBrowserHistory } from "history";
<BrowserRouter history={history}>
...
这是通过这样的Express服务器(server.js)提供的服务...
//for build
// Serve the static files from the React app
app.use(express.static(path.join(__dirname, 'build')));
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
这在本地运行正常,我可以成功导航到任何路线。 部署到生产环境后,如果我导航到路线,则会得到
Cannot GET /Sites/SiteDashboard/
我的项目结构如下,这是标准的CRA安装...
我遇到的问题是指向生产版本上的正确位置,以指向index.html(或其他内容),以便像在本地运行(npm start)一样访问历史记录。
谁能建议我需要指向的地方。
谢谢。