httprouter
httprouter copied to clipboard
Serve React Router
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 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
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.