To implement basic server-side rendering, we will need to import the following React, React Router, and Material-UI-specific modules into the server code. In our code structure, these modules will be imported into server/express.js:
- React modules: Required to render the React components and use renderToString:
import React from 'react'import ReactDOMServer from 'react-dom/server'
-
Router modules: The StaticRouter is a stateless router that takes the requested URL to match the frontend route and the MainRouter component, which is the root component in our frontend:
import StaticRouter from 'react-router-dom/StaticRouter'import MainRouter from './../client/MainRouter'
- Material-UI modules: The following ...