code: function RouteStatus(props) {
    return (
      <Route
        render={({ staticContext }) => {
          // we have to check if staticContext exists
          // because it will be undefined if rendered through a BrowserRouter
          if (staticContext) {
            staticContext.statusCode = props.statusCode;
          }
  
          return <div>{props.children}</div>;
        }}
      />
    );
  }
docs: This example renders a route within a StaticRouter and populates its staticContext, which it then prints out. In the real world you would use the StaticRouter for server-side rendering:  import express from "express"; import ReactDOMServer from "react-dom/server";  const app = express()  app.get('*', (req, res) => { let staticContext = {}  let html = ReactDOMServer.renderToString( <StaticRouter location={req.url} context={staticContext}> <App /> (includes the RouteStatus component below e.g. for 404 errors) </StaticRouter> );  res.status(staticContext.statusCode || 200).send(html); });  app.listen(process.env.PORT || 3000);