Lot of questions have been asked on the same topic like this and this, but I could not solve my problem.
The react-app works good without reload, but when reloaded or manual refresh is done on an nested react-router URL, it breaks.
Here is my routes:
ReactDOM.render(
<Provider store={store}>
<Router history={history}>
<Route path='/' component={App}>
<IndexRoute component={GoogleLoginComponent} />
<Route path='home' component={HomeComponent} onEnter={authRequired.bind(this, store)}>
</Route>
<Route path='register' component={RegisterComponent} onEnter={authRequired.bind(this, store)}>
</Route>
<Route path='eventCreated/eventId=:eventId' component={EventShareComponent}>
</Route>
<Route path='event/eventId=:eventId' component={EventPageComponent}>
</Route>
</Route>
</Router>
</Provider>,
document.getElementById('app')
);
When I reload on http://localhost:3000/home or http://localhost:3000/register, the app reloads smoothly.
But when I try to reload http://localhost:3000/eventCreated/eventId=1234 or http://localhost:3000/event/eventId=1234, it breaks and gives the following in console.
I think the nested Urls are not identified by web-pack and I have changed the server.js file like this:
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: {
index: 'index.html',
rewrites: [
{ from: /\/event/, to: 'index.html'}
]
}
}).listen(PORT, function(err, result) {
if (err) console.log(err);
console.log('Listening at port '+ PORT);
});
I have rewritten the nested urls to redirect to index.html, but still could not figure out what is the error. I have aslo tried making historyApiFallback to true.