N
N
Nikita Shchypylov2018-02-19 16:30:18
React
Nikita Shchypylov, 2018-02-19 16:30:18

Why does React-router break when updating?

Hello everyone
I decided to make a new project on my own webpack and for some reason the router started to break down during the update. That is, on a click on the Link, it renders the component, but if I refresh the page, I get Cannot GET /login
Webpack:

const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  devtool: 'eval-source-map',
  entry: [
    'webpack-dev-server/client?http://localhost:3000',
    'webpack/hot/only-dev-server',
    'react-hot-loader/patch',
    path.join(__dirname, 'client/index.js')
  ],
  output: {
    path: path.join(__dirname, '/dist/'),
    filename: '[name].js',
    publicPath: '/'
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: 'client/index.html',
      inject: 'body',
      filename: 'index.html'
    }),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify('development')
    })
  ],
  module: {
    loaders: [
      {
        test: /\.js?$/,
        exclude: /node_modules/,
        loader: "babel-loader"
      },
      {
        test: /\.json?$/,
        loader: 'json'
      },
      {
        test: /\.scss$/,
        loader: 'style!css!sass?modules&localIdentName=[name]---[local]---[hash:base64:5]'
      },
      { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader?limit=10000&minetype=application/font-woff" },
      { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" }
    ]
  }
};

Router :
index.js 
ReactDOM.render(<BrowserRouter><App/></BrowserRouter>, document.getElementById("root"));

app.js :
<Switch>
            <Route exact path='/' render={() => <div><Header/><Map/></div>}/>
            <Route exact path='/login' component={Login}/>
          </Switch>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2018-02-19
@Nikulio

try adding to the config:

devServer: {
    historyApiFallback: true,
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question