有关此处的预渲染的新手,所以我正在关注本教程: https://medium.com/superhighfives/an-almost-static-stack-6df0a2791319
然后我说到react-snapshot
构建静态HTML的地步。
在生成的HTML上,body
如下所示:
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script>!function(l){function e(e){for(var r,t,n=e[0],o=e[1],u=e[2],f=0,i=[];f<n.length;f++)t=n[f],p[t]&&i.push(p[t][0]),p[t]=0;for(r in o)Object.prototype.hasOwnProperty.call(o,r)&&(l[r]=o[r]);for(s&&s(e);i.length;)i.shift()();return c.push.apply(c,u||[]),a()}function a(){for(var e,r=0;r<c.length;r++){for(var t=c[r],n=!0,o=1;o<t.length;o++){var u=t[o];0!==p[u]&&(n=!1)}n&&(c.splice(r--,1),e=f(f.s=t[0]))}return e}var t={},p={2:0},c=[];function f(e){if(t[e])return t[e].exports;var r=t[e]={i:e,l:!1,exports:{}};return l[e].call(r.exports,r,r.exports,f),r.l=!0,r.exports}f.m=l,f.c=t,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(r,e){if(1&e&&(r=f(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var n in r)f.d(t,n,function(e){return r[e]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var r=window.webpackJsonp=window.webpackJsonp||[],n=r.push.bind(r);r.push=e,r=r.slice();for(var o=0;o<r.length;o++)e(r[o]);var s=n;a()}([])</script><script src="/static/js/1.2664f19e.chunk.js"></script><script src="/static/js/main.4acc5dad.chunk.js"></script>
</body>
您可以看到"root"
div为空,这与介质上显示整个DOM的示例不同:
<body>
<div id="root">
<div class="App" data-reactroot="" data-reactid="1" data-react-checksum="1438355234">
<div class="App-header" data-reactid="2">
<img src="/static/media/logo.5d5d9eef.svg" class="App-logo" alt="logo" data-reactid="3">
<h2 data-reactid="4">Welcome to React</h2>
</div>
<p class="App-intro" data-reactid="5">
<!-- react-text: 6 -->To get started, edit <!-- /react-text -->
<code data-reactid="7">src/App.js</code>
<!-- react-text: 8 --> and save to reload.<!-- /react-text -->
</p>
</div>
</div>
<script type="text/javascript" src="/static/js/main.69baff85.js"></script>
</body>
我想念什么?我需要body
是静态的。
答案 0 :(得分:0)
由于render
中App.js
方法内部的情况,快照丢失。消除条件可以解决问题。