3

I render react component on server and when go to route get error message:

enter image description here

  const renderToString = ReactDOMServer.renderToString
  const fac = React.createFactory(React.createClass({
    render: function() { 
      return (
        <Provider store={store}>
          <StaticRouter location={location} context={routeContext}>
            <App />
          </StaticRouter>
        </Provider>
      )
  }}))

  const appHtml = renderToString(fac())
Khotey Vitaliy
  • 509
  • 1
  • 6
  • 18

1 Answers1

8

I suggest you write it like this:

const ReactDOMServer = require('react-dom/server');
const appHtml = ReactDOMServer.renderToStaticMarkup (
    <Provider store={store}>
      <StaticRouter location={location} context={routeContext}>
        <App />
      </StaticRouter>
    </Provider>
);

I hope it helps you.

alireza
  • 518
  • 5
  • 15