404 error on react js application page when we reload/refresh

I have created a site using react js. It is working fine on my local system using browserHistory but not working on my production server. The first time it loads properly. When I refresh the page it gives me “page not found” error.

I have tried using hashHistory. It resolved my issue but I am looking for a better solution because I don’t want complex URL hashHistory gives.

My webpack.config.js code –

module.exports = {
  entry: [
    './src/index.js'
  ],
  output: {
    path: __dirname,
    publicPath: '/',
    filename: 'bundle.js'
  },
  module: {
    loaders: [{
      exclude: /node_modules/,
      loader: 'babel'
    }]
  },
  resolve: {
    extensions: ['', '.js', '.jsx']
  },
  devServer: {
    historyApiFallback: true,
    contentBase: './',
    port: 3000
  }
};

Read more here: 404 error on react js application page when we reload/refresh

Leave a Reply

Your email address will not be published. Required fields are marked *