1

BrowserHistory (react-router v4) returns 404 and historyApiFallback not working.

So when I go to http://localhost:3000/app I get a 404. I tried the following solutions with no avail... any ideas? I also tried setting historyApiFallback to true and not using a relative path for bundle.js i.e. /static/bundle.js in index.html

historyApiFallback doesn't work in Webpack dev server historyApiFallback doesn't work, for scripts, if you're nested multiple path sections deep

Index.html

    `<script src="bundle.js"></script`>

Webpack output

output: {
 path: path.join(__dirname, 'public'),
 filename: 'bundle.js',
 publicPath: '/'
},

Webpack devServer

historyApiFallback: { index: 'public/index.html' },
Blackstone4
  • 631
  • 8
  • 20

1 Answers1

1

Embarrassingly it turns out I hadn't correctly setup my Express server routing. I used the same setup from a tutorial which was based on HashRouter....

I added the following to my server.js and it worked!

app.get('*', (req, res) => {
 res.sendFile(path.join(__dirname, 'public/index.html'));
});
Blackstone4
  • 631
  • 8
  • 20