historyApiFallback doesn't work in Webpack dev server historyApiFallback doesn't work in Webpack dev server javascript javascript

historyApiFallback doesn't work in Webpack dev server


I meet the same question today.let config in webpack.config.js: output.publicPath be equal to devServer.historyApiFallback.index and point out html file route。my webpack-dev-server version is 1.10.1 and work well. http://webpack.github.io/docs/webpack-dev-server.html#the-historyapifallback-option doesn't work, you must point out html file route.

for example

module.exports = {    entry: "./src/app/index.js",    output: {        path: path.resolve(__dirname, 'build'),        publicPath: 'build',        filename: 'bundle-main.js'    },    devServer: {        historyApiFallback:{            index:'build/index.html'        },    },};

historyApiFallback.index indicate that when url path not match a true file,webpack-dev-server use the file config in historyApiFallback.index to show in browser rather than 404 page. then all things about your route change let your js using react-router do it.


output: {    ...    publicPath: "/"  },

Adding public path solved this for me


I had this problem and was only able to fix it using index: '/' with webpack 4.20.2

        historyApiFallback: {            index: '/'        }