I\'m creating an app that uses webpack-dev-server in development alongside react-router.
It seems that webpack-dev-server is built around the assumption that you wil
If you're running webpack-dev-server using CLI, you can configure it through webpack.config.js passing devServer object:
module.exports = {
entry: "index.js",
output: {
filename: "bundle.js"
},
devServer: {
historyApiFallback: true
}
}
This will redirect to index.html everytime it 404 is encountered.
NOTE: If you're using publicPath, you'll need to pass it to devServer too:
module.exports = {
entry: "index.js",
output: {
filename: "bundle.js",
publicPath: "admin/dashboard"
},
devServer: {
historyApiFallback: {
index: "admin/dashboard"
}
}
}
You can verify that everything is setup correctly by looking at the first few lines of the output (the part with "404s will fallback to: path").