Search code examples
reactjswebpackreact-routerwebpack-2

Webpack 2 with historyApiFallback Not Working


I keep getting Cannot GET /task I tried to modify my webpack with solutions I found here but I still get it.

var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
    entry: './src/app.js',
    output: {
        path: __dirname + '/dist',
        filename: 'app.bundle.js'
    },
    module: {
        rules: [
            {
                test: /\.s?css$/,
                use: ['style-loader', 'css-loader', 'sass-loader']
            }, {
                test: /\.js$/,
                exclude: /node_modules/,
                use: 'babel-loader'
            }, {
                test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
                loader: 'file-loader?name=fonts/[name].[ext]'
            }
        ]
    },
    devServer: {
        historyApiFallback: {
            index: '/index.html'
        },
        stats: true,
        inline: true,
        progress: true
    }
    plugins: [new HtmlWebpackPlugin({template: './src/index.html'})]
}

Solution

  • I think client gets index.html only when path is /.

    Try to use this setting.

    devServer: {
        historyApiFallback: true
    }