F
F
FaIcon2017-04-04 22:08:24
Express.js
FaIcon, 2017-04-04 22:08:24

react+express. How to connect together?

I started to understand with React, and I had questions. Now there is an application on react (with browser-based routing) and an express server on a different port. They communicate and everything works well. I want to add server rendering so that the server decides which pages to give to whom (there is authorization). But I can't figure out how to put react and express together. What exactly do I want:

  1. The browser makes a request to the server
  2. The server decides what to serve and only serves the current page
  3. When changing the url, the browser sends a request to the server (without reloading), receives html (or a new bundle file) and redraws the page

Google couldn't help. I watched how it works on Instagram, where html is not loaded at all, requests go only for data.
Do I understand correctly that the React application cannot be divided into separate pages, which, as necessary, will be loaded from the server? I understand that the entire site (all pages) is packed into one bundle.js file, and then rendered from there, and renderToString is used only to speed up loading on the first request.
If it can be shared, please tell me how. For example, I have three pages: Main, News, About. I want that when changing the url, html is loaded from the server and the page is redrawn (without reloading). At the same time, so that only the logic of the components remains in the bundle (otherwise, there is no point in loading from the server).

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question