Reactjs HistoryLocation get 404 on refresh

722 Views Asked by At

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.

0

There are 0 best solutions below