React slingshot - Webpack hot middleware returning 404 on hot-update.json when using react router sub-routes

3.3k Views Asked by At

Im using the react slingshot starter project for my react/redux app. Hot reload works great when I use routes like /foo but I've found that hot reload isn't working on subroutes like /foo/bar. I haven't made any changes to the out-of-the-box webpack config file, which can be found here https://github.com/coryhouse/react-slingshot/blob/master/webpack.config.js

I get 404 GET http://localhost:3004/orders/c344e97ed1fbc2923017.hot-update.json 404 (Not Found)on the CreateOrder component when I have the following routes configuration:

<Route path="/" component={App}>
    <Route path="login" component={Login} />
    <Route path="orders" component={OrderPanel} />
    <Route path="orders/create" component={CreateOrder} />
    <Route path="*" component={NotFoundPage} />
</Route>

But when I change the path from orders/create to just create, it doesn't returns a 404.

It seems like the hot update middleware is trying to fetch the hot-update.json from the /orders subroute?

2

There are 2 best solutions below

2
On BEST ANSWER

Just for completeness and anyone having this problem with an older version of slingshot. This was also mentioned in issue 75 and fixed here by replacing:

publicPath: '',

with

publicPath: '/',

in webpack.config.js

UPDATE: From reduckted's comment the publicPath has to start and end with a slash. Replace:

publicPath: 'dist/',

with

publicPath: '/dist/',
0
On

publicPath config wasn't an issue for me. If you are using redux can try this.

For some random reason redux-devtools was not allowing hot reload for me. Try removing it from root component and redux compose config.

Note: Use redux devtool browser extension with this config in your store configuration: window.devToolsExtension ? window.devToolsExtension() : f => f

Also, must read: https://medium.com/@rajaraodv/webpacks-hmr-react-hot-loader-the-missing-manual-232336dc0d96#.ejpsmve8f

Or try hot reload 3: example: https://github.com/gaearon/redux-devtools/commit/64f58b7010a1b2a71ad16716eb37ac1031f93915