DEV Community

Cover image for Fixing the "cannot GET /URL" error on refresh with React Router (or how client side routers work)

Fixing the "cannot GET /URL" error on refresh with React Router (or how client side routers work)

Tyler McGinnis on February 05, 2018

A very common error developers run into when building (and specifically refreshing) an app with React Router is 'Cannot GET /url'. In this post we'...
Collapse
 
leoelicos profile image
Leo Wong

Hey I just wanted to say thank you so much for this post, it fixed a bug that nobody on my bootcamp course could fix - by adding a catch-all, I was getting an error after returning from Stripe checkout,

Cannot GET /success

, but after adding the Express catch-all as you suggested:

app.get('/*', (req, res) => {
  res.sendFile(path.join(__dirname, '../client/build/index.html'), (err) => err && res.status(500).send(err));
});
Enter fullscreen mode Exit fullscreen mode

…it worked

Collapse
 
sushant0808 profile image
sushant0808

Can you please share how exactly did you solve this error. I put this in my node application but still didn't work for me. Should I make changes to my frontend react app in the router or any other changes that you made that worked for you. Please help me with this one

Collapse
 
leoelicos profile image
Leo Wong

Only the backend... What's your repo?

Collapse
 
joncassdev profile image
Jonathan Cass

Nice post, thanks. Can you expand on why the HashRouter is to be avoided?