Reactjs HistoryLocation get 404 on refresh

无人久伴 提交于 2020-02-05 08:03:16

问题


I'm building an app in Laravel and just started doing front end UI with reactjs.

After I enabled HistoryLoaction in react-router, whenever I refresh a page, it doesnt stay the same displaying the components rendered from react, instead, it hits my api endpoints and returns data in json back in the browser.

I figured its because my backend api routes and react routes are the same. But if I make the backend routes different from the react routes, it'll just get "http not found" on refresh instead.

Is there a way to prevent this in react, react-router or laravel? maybe a way to make the page rerender the components on page refresh?

Update:

In react-router doc, it says you must configure your server to use HistoryLocation. But I dont quite understand how to configure. does it mean I need to direct all requests to one view? Then how do I make GET and POST request in react components?

Thanks.

来源:https://stackoverflow.com/questions/30940581/reactjs-historylocation-get-404-on-refresh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!