Javascript reactjs示例中出现多个错误

Javascript reactjs示例中出现多个错误,javascript,node.js,reactjs,Javascript,Node.js,Reactjs,我得到以下错误: bundle.js:1079 Warning: render(): Rendering components directly into document.body is discouraged, since its children are often manipulated by third-party scripts and browser extensions. This may lead to subtle reconciliation issues. Try ren

我得到以下错误:

bundle.js:1079 Warning: render(): Rendering components directly into document.body is discouraged, since its children are often manipulated by third-party scripts and browser extensions. This may lead to subtle reconciliation issues. Try rendering into a container element created for your app.printWarning @ bundle.js:1079warning @ bundle.js:1103_renderSubtreeIntoContainer @ bundle.js:11201render @ bundle.js:11271181../components/LoginForm/index.jsx @ bundle.js:20603s @ bundle.js:1e @ bundle.js:1(anonymous function) @ bundle.js:1
bundle.js:1079 Warning: render(): Target node has markup rendered by React, but there are unrelated nodes as well. This is most commonly caused by white-space inserted around server-rendered markup.printWarning @ bundle.js:1079warning @ bundle.js:1103_renderSubtreeIntoContainer @ bundle.js:11241render @ bundle.js:11271181../components/LoginForm/index.jsx @ bundle.js:20603s @ bundle.js:1e @ bundle.js:1(anonymous function) @ bundle.js:1
bundle.js:1079 Warning: validateDOMNesting(...): <html> cannot appear as a child of <body>. See body > App > html.printWarning @ bundle.js:1079warning @ bundle.js:1103validateDOMNesting @ bundle.js:17187mountComponent @ bundle.js:7165mountComponent @ bundle.js:12249performInitialMount @ bundle.js:6038mountComponent @ bundle.js:5925mountComponent @ bundle.js:12249performInitialMount @ bundle.js:6038mountComponent @ bundle.js:5925mountComponent @ bundle.js:12249mountComponentIntoNode @ bundle.js:10953perform @ bundle.js:14898batchedMountComponentIntoNode @ bundle.js:10975perform @ bundle.js:14898batchedUpdates @ bundle.js:9984batchedUpdates @ bundle.js:13020_renderNewRootComponent @ bundle.js:11169_renderSubtreeIntoContainer @ bundle.js:11250render @ bundle.js:11271181../components/LoginForm/index.jsx @ bundle.js:20603s @ bundle.js:1e @ bundle.js:1(anonymous function) @ bundle.js:1
bundle.js:1079 Warning: Unknown DOM property charset. Did you mean charSet?
    in meta (created by App)
    in head (created by App)
    in html (created by App)
    in AppprintWarning @ bundle.js:1079warning @ bundle.js:1103validateProperty @ bundle.js:9503warnUnknownProperties @ bundle.js:9521handleElement @ bundle.js:9545onBeforeMountComponent @ bundle.js:9550callHook @ bundle.js:9587emitEvent @ bundle.js:9599onBeforeMountComponent @ bundle.js:9876mountComponent @ bundle.js:12246mountChildren @ bundle.js:11627_createContentMarkup @ bundle.js:7337mountComponent @ bundle.js:7204mountComponent @ bundle.js:12249mountChildren @ bundle.js:11627_createContentMarkup @ bundle.js:7337mountComponent @ bundle.js:7204mountComponent @ bundle.js:12249performInitialMount @ bundle.js:6038mountComponent @ bundle.js:5925mountComponent @ bundle.js:12249performInitialMount @ bundle.js:6038mountComponent @ bundle.js:5925mountComponent @ bundle.js:12249mountComponentIntoNode @ bundle.js:10953perform @ bundle.js:14898batchedMountComponentIntoNode @ bundle.js:10975perform @ bundle.js:14898batchedUpdates @ bundle.js:9984batchedUpdates @ bundle.js:13020_renderNewRootComponent @ bundle.js:11169_renderSubtreeIntoContainer @ bundle.js:11250render @ bundle.js:11271181../components/LoginForm/index.jsx @ bundle.js:20603s @ bundle.js:1e @ bundle.js:1(anonymous function) @ bundle.js:1
bundle.js:1079 Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
 (client) <meta data-reactid="3
 (server) <div data-reactid="6"printWarning @ bundle.js:1079warning @ bundle.js:1103_mountImageIntoNode @ bundle.js:11356mountComponentIntoNode @ bundle.js:10961perform @ bundle.js:14898batchedMountComponentIntoNode @ bundle.js:10975perform @ bundle.js:14898batchedUpdates @ bundle.js:9984batchedUpdates @ bundle.js:13020_renderNewRootComponent @ bundle.js:11169_renderSubtreeIntoContainer @ bundle.js:11250render @ bundle.js:11271181../components/LoginForm/index.jsx @ bundle.js:20603s @ bundle.js:1e @ bundle.js:1(anonymous function) @ bundle.js:1
bundle.js:826 Uncaught Error: Unable to find element with ID 2.(…)

您需要像这样将此html传递到html模板中

const App = React.createFactory(AppComponent);
const html = ReactDOMServer.renderToString(App({}));
res.status(200).send(renderFullPage(html, null));

function renderFullPage(html, initialState) {
  return `
    <!doctype html>
    <html lang="en">
      <head>

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
        <title>React</title>
      </head>
      <body>
        <div id="root">${html}</div>
        <script>
          window.__INITIAL_STATE__ = ${JSON.stringify(initialState)}
        </script>
        <script src="/static/bundle.js"></script>
      </body>
    </html>
  `
}
const-App=React.createFactory(AppComponent);
consthtml=ReactDOMServer.renderToString(App({}));
res.status(200).send(renderFullPage(html,null));
函数renderFullPage(html,initialState){
返回`
反应
${html}
window.\uuuu INITIAL\u STATE\uuuu=${JSON.stringify(initialState)}
`
}
ReactDOM.render(<App />, document.getElementById('root'));
<html>

<head>
  <meta charset="utf-8" />
  <title>index.html</title>
</head>

<body>
  <div id="root"></div>
  <script src="static/bundle.js"></script>
</body>

</html>
const App = React.createFactory(AppComponent);
const html = ReactDOMServer.renderToString(App({}));

res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.status(200)
  .send(html);
const App = React.createFactory(AppComponent);
const html = ReactDOMServer.renderToString(App({}));
res.status(200).send(renderFullPage(html, null));

function renderFullPage(html, initialState) {
  return `
    <!doctype html>
    <html lang="en">
      <head>

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
        <title>React</title>
      </head>
      <body>
        <div id="root">${html}</div>
        <script>
          window.__INITIAL_STATE__ = ${JSON.stringify(initialState)}
        </script>
        <script src="/static/bundle.js"></script>
      </body>
    </html>
  `
}