Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDeni Chan
Courses Plus Student 19,384 PointsReact router. Cannot GET when refreshing a page or write url manually
I am trying to build a SPA with react router. When I am navigating with link it works perfect, but with refreshing or writting url it gives me cannot GET /(any route except main). I was trying to add historyApiFallback : true option to my webpack dev server configs but it didnt solved it.
I will appreciate any help.
1 Answer
akak
29,445 PointsHi. You need either use hashHistory, or if you want to use browserHistory have a server with catch all that always returns index.html and from there react router takes in and gets you to the right route. For testing and dev I usually use hashHistory to avoid server hassle, and then change to browserHistory before going to production. You can find more info here. https://css-tricks.com/learning-react-router/#article-header-id-9 and https://github.com/reactjs/react-router/blob/master/docs/guides/Histories.md#configuring-your-server
Cheers!
Deni Chan
Courses Plus Student 19,384 PointsDeni Chan
Courses Plus Student 19,384 PointsMany thanks man! Yes, I figured out that with Hashhistory it works fine.But I want my url looks nice. I saw that link that you put and I tried to implement express server like there but after that my ajax reqests stoped work