带有historyApiFallback无效的Webpack 2

时间:2017-07-04 17:57:47

标签: reactjs webpack react-router webpack-2

我不断获得Cannot GET /task我尝试使用我在此处找到的解决方案来修改我的网络包,但我仍然可以使用它。

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'})]
}

1 个答案:

答案 0 :(得分:1)

我认为只有当路径为index.html时,客户才会获得/

尝试使用此设置。

devServer: {
    historyApiFallback: true
}