historyApiFallback doesn't work in Webpack dev server

后端 未结 4 844
小鲜肉
小鲜肉 2020-12-05 07:09

I use Webpack dev server and browserHistory in React Router to manipulate with urls by HTML5 History API. historyapifallback-option does not work in my webpack config file.

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 07:47

    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.

提交回复
热议问题