Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack-dev-server react-router push state

I am trying to get react-router to work with webpack-dev-server but keep getting cannot Get /SOMEURL. This is because webpack-dev-server is looking for that specific file but cannot find it. I'd like webpack to resort to using react-router vs searching for the files itself.

How can I set that up?

My grunt:

'webpack-dev-server': {
      options: {
        hot: true,
        port: 8000,
        webpack: webpackDevConfig,
        publicPath: '/assets/',
        contentBase: './<%= pkg.src %>/'
      },

      start: {
        keepAlive: true,
      }
    },
like image 863
Mohamed El Mahallawy Avatar asked Mar 08 '15 05:03

Mohamed El Mahallawy


2 Answers

For me, i had this in my index file:

<script src="./assets/app.js"></script>

rather than

 <script src="/assets/app.js"></script>

So, it looks like the history fallback API was in competition with my misconfiguration.

like image 171
ReduxDJ Avatar answered Oct 18 '22 02:10

ReduxDJ


Use the --history-api-fallback option to webpack-dev-server. This uses connect-history-api-fallback to serve up index.html if the route doesn't match any other files. (This does mean you have to use index.html as the filename for your HTML page.)

like image 36
Michelle Tilley Avatar answered Oct 18 '22 02:10

Michelle Tilley