Trong Lam Phan
Trong Lam Phan

Reputation: 2412

Webpack-dev-server sub pages not found

I'm using react with webpack. My app worked well before using webpack-dev-server. Only the home page works now, the others return "404 not found". Maybe there's a problem in webpack.config.js ?

var webpack = require("webpack");
var path = require("path");

var BUILD_DIR = path.resolve(__dirname, "public");
var APP_DIR = path.resolve(__dirname, "app");

var config = {
    entry: [
        "webpack/hot/only-dev-server",
        APP_DIR + "/main.js",
        "webpack-dev-server/client?localhost:8080"
    ],

    output: {
        path: BUILD_DIR + "/dist",
        filename: "bundle.js",
    },

    plugins: [
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery"
        }),
        new webpack.HotModuleReplacementPlugin()
    ],

    module: {
        loaders: [...],
    },

    devServer: {
        noInfo: true,
        hot: true,
        inline: true
    },
}

module.exports = config;

And my script in package.json:

"start": "webpack --watch & webpack-dev-server --content-base public"

Webpack generates well bundle file. So i think the webpack-dev-server is the one who causes this problem.

Thank you !

Upvotes: 1

Views: 2032

Answers (2)

Trong Lam Phan
Trong Lam Phan

Reputation: 2412

I've found the answer. For someone who has the same problem, we need to add "historyApiFallback: true" to devServerConfig:

devServer: {
    noInfo: true,
    hot: true,
    inline: true,
    historyApiFallback: true
},

Upvotes: 4

Jason
Jason

Reputation: 1309

can you change your npm script

"start": "webpack --watch & webpack-dev-server --content-base public"

to

"start": "webpack --watch & webpack-dev-server --content-base public/"

and see what happens? Otherwise I will comeback and assist you.

Upvotes: 0

Related Questions