Skip to content Skip to sidebar Skip to footer

Webpack HistoryApiFallback Configuration For Deep Routes

webpack-dev-server can be set up to send you back to index.html and find your scripts for a single route like http://localhost:4301/sdr but when you put in a deeper route (or a sin

Solution 1:

I also had this issue. I found the solution was to add publicPath: '/' to my webpack config under output.

const base = {
  entry: [
    PATHS.app,
  ],
  output: {
    path: PATHS.build,
    publicPath: '/',
    filename: 'index_bundle.js',
  },
  module: {
    loaders: [
      {test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'},
      {test: /\.css$/, loader: 'style!css?sourceMap&modules&localIdentName=[name]__[local]___[hash:base64:5]'},
      {test: /\.json$/, loader: 'json'},
    ],
  },
  resolve: {
    root: path.resolve('./app'),
  },
}

const developmentConfig = {
  devtool: 'cheap-module-inline-source-map',
  devServer: {
    contentBase: PATHS.build,
    hot: true,
    inline: true,
    progress: true,
    proxy: {
      '/api': 'http://127.0.0.1:5000',
    },
    historyApiFallback: true,
  },
  plugins: [HTMLWebpackPluginConfig, new webpack.HotModuleReplacementPlugin()],
}

export default Object.assign({}, base, developmentConfig)

Here is more detailed documentation of this property: http://webpack.github.io/docs/configuration.html#output-publicpath

Here is the forum where there is a more detailed discussion of this issue: https://github.com/webpack/webpack/issues/443


Post a Comment for "Webpack HistoryApiFallback Configuration For Deep Routes"