How to configure webpack dev server with react router dom v4?

后端 未结 2 1556
面向向阳花
面向向阳花 2020-12-15 16:50

This is the code of my webpack configuration:

const compiler = webpack({
  entry: [\'whatwg-fetch\', path.resolve(__dirname, \'js\', \'app.js\')], 
  module         


        
相关标签:
2条回答
  • 2020-12-15 17:11

    In my case I had to remove proxy config, because the webpack server wanted a response from http://localhost:3001.

    // proxy: {
    //   '/': 'http://localhost:3001',
    // },
    
    0 讨论(0)
  • 2020-12-15 17:18

    I do not think it has anything to do with webpack-config. Here is a basic github repository using react-router-4.0. I have created this example without any specific changes related to react-router-4.0 in webpack config.

    Add 'devServer' in your webpack config if not already:

    devServer: {
        historyApiFallback: true,
      }
    

    Two small suggestions in your code, try using 'exact' with the path for 'about' i.e.

    <Route exact path='/about' component={About}/>
    

    and, add parenthesis for const about i.e.,

    const About = () => (<div> <h1>About</h1> </div>);
    

    Hope, this solves your query. Let me know if you require any other information on this.

    0 讨论(0)
提交回复
热议问题