Ben
Ben

Reputation: 151

React router capturing too many paths

I used create-react-app to bootstrap my project.

I added react-router to my react app. After I build and serve using serve -s build, when I go to any path such as http://localhost:5000/favicon.ico, it takes me to my index, which means the URL change is being captured by react-router. However once I'm there, if I force reload the page with CMD+SHIFT+R then the static file loads as expected. How do I make this behavior the default?

Upvotes: 1

Views: 58

Answers (1)

Ben
Ben

Reputation: 151

According to the FAQ, when a site is served statically it needs to use HashRouter instead of BrowserRouter https://github.com/ReactTraining/react-router/blob/master/FAQ.md

I also had to disable the service worker by commenting out two lines in src/index.js since it was caching everything all the time.

Making that change fixed my problem!

Upvotes: 1

Related Questions