BrowserHistory (react-router v4) 返回 404 并且 historyApiFallback 不工作。
所以当我去 http://localhost:3000/app我收到 404。我尝试了以下解决方案但无济于事……有什么想法吗?我还尝试将 historyApiFallback 设置为 true 并且不使用 bundle.js 的相对路径,即 index.html 中的/static/bundle.js
historyApiFallback doesn't work in Webpack dev server historyApiFallback doesn't work, for scripts, if you're nested multiple path sections deep
Index.html
`<script src="bundle.js"></script`>
Webpack 输出
output: {
path: path.join(__dirname, 'public'),
filename: 'bundle.js',
publicPath: '/'
},
Webpack 开发服务器
historyApiFallback: { index: 'public/index.html' },
最佳答案
令人尴尬的是,我没有正确设置我的 Express 服务器路由。我使用了基于 HashRouter 的教程中的相同设置....
我将以下内容添加到我的 server.js 并且它起作用了!
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'public/index.html'));
});
关于javascript - BrowserHistory (react-router v4) 返回 404 并且 historyApiFallback 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45580723/