Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
123 views
in Technique[技术] by (71.8m points)

node.js - How to make API calls server side REACT?

I am trying to render my react app server side for better SEO and better performance but since most of the content of the site is from an API and the API call is still happening on the client side the server is returning an almost black HTML template is there a way to make the API calls in server

P.S. I'm not using Redux

question from:https://stackoverflow.com/questions/66063415/how-to-make-api-calls-server-side-react

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is exactly what React as client and Express as server must do. When you choose to develop your frontend by React and use 'npm build' to get output from your whole React project. you get only "ONE" index.html file. so you can't render multiple html pages by Express. you can only render the main html file and use api's to render other routes. That's why you can't do such a thing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...