httprouter icon indicating copy to clipboard operation
httprouter copied to clipboard

Serve React Router

Open Dominik-Robert opened this issue 5 years ago • 2 comments

I was able to serve a react app which I created with "create-react-app", but how I serve an app which is created with "create-react-app" and has react router? Is this possible?

Dominik-Robert avatar Apr 01 '19 04:04 Dominik-Robert

@Dominik-Robert from my understanding, you just need to serve index.html using wildcard, routing will be handled on the frontend by react-router. If u're talking about server-side rendering for react app, this is not the library that serves such purpose

stanleynguyen avatar Apr 19 '19 17:04 stanleynguyen

You need to have an fallback to index.html in case of direct accessing your SPA routes. If /some/page is handled by react and not by the server, the server needs to serve the index.html and let then react itself decide what to do with the path at the visitors browser.

In case of SEO and initial load times it is a good idea to let a node server pre rendering the SPA. Thats called server side rendering (SSR). This way your go application will only serve the api, not the static files or the SPA.

hbroer avatar May 07 '19 09:05 hbroer