- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
这基本上是我的所有代码。我正在运行 Hapi 并尝试使用 react-loadable 来服务器渲染我的 React 应用程序。
我在代码 here 中添加了很多缺失的部分.
const location = req.url.pathname
const context = {}
const modules = []
const Router = () => (
<Switch>
<Route exact path="/" component={Home} />
<Route path="/login" component={Login} />
<Route path="/me" component={Profile} />
<Route component={NotFound} />
</Switch>
)
const App = () => (
<StaticRouter location={location} context={context}>
<main>
<Header />
<Router />
<Footer />
</main>
</StaticRouter>
)
const preloadables = [ Home, Login, Profile, NotFound ]
await Promise.all(preloadables.map(preloadable => preloadable.preload()))
const html = ReactDOMServer.renderToString(
<Loadable.Capture report={moduleName => modules.push(moduleName)}>
<App/>
</Loadable.Capture>
)
// render html
它正确地呈现页面,因为我看到我的 React 应用程序在我的浏览器中呈现。尽管除非我禁用服务器上的缓存,否则我看不到“路由器”的任何内容。所以第一个请求没有渲染路由器,接下来的请求会。
在服务器上,console.log('modules:', modules)
总是返回 modules: []
。不管缓存。因此,即使我禁用缓存,刷新页面两次以查看路由器是否正常工作,模块仍然是空的。
npm run start:server
Warning: setState(...): Can only update a mounting component. This usually means you called setState() outside componentWillMount() on the server. This is a no-op.
Please check the code for the LoadableComponent component.
modules []
modules []
modules []
modules []
modules []
我有点迷茫,因为它应该可以工作.. 一切看起来都很好。
最佳答案
今天不知怎么折腾了好久,终于解决了。
在获得模块之前,您必须正确编写可加载组件。官方文档声明here
Loadable({
loader: () => import('./Bar'),
modules: ['./Bar'],
webpack: () => [require.resolveWeak('./Bar')],
});
或者你可以使用提供的 babel 插件。但是,就我而言,我正在使用 ts-node 并且没有使用该 babel 插件的运气,因此只有选项 1 可用。
写在这里,因为有人会遇到类似的问题。
(p.s. lodable-component
也依赖 babel 插件)
关于node.js - Loadable.Capture 不报告任何模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51224604/
我一直在阅读 Captures这一段引起了我的兴趣: Inside a Signature, a Capture may be created by prefixing a sigilless par
我在 Java 中使用这个正则表达式: ^(Mon(?:.?|day)?)(?:[\.,])?$ (可以测试 here ) 我想捕获日期,后跟可选的 . 或 ,。如果是星期一,我想捕获 Monday
我正在 try catch 功能键 F1 到 F12 和 4 个箭头键以及主页、插入、删除、结束、向上翻页和向下翻页键。如何???? private void Form1_KeyPress(objec
没有capture="camera" input type="file" 的属性标签 in official w3.org documentation . 讽刺的是,我发现了这么多地方 capture
摘自Huon Wilson的Finding Closure in Rust: Capturing entirely by value is also strictly more general tha
所以我想这样做: public interface IFieldObject { public Comparable get(); } public interface IFieldCondi
我希望使用正则表达式将单词分成组(vowels, not_vowels, more_vowels),使用标记来确保每个单词以元音开头和结尾。 import re MARKER = "~" VOWELS
我在浏览 StackOverflow 时发现了 Szimek/Signature_Pad 以使用 Javascript 捕获电子/数字签名。 我研究过,但我仍然对如何将 DATA URI 捕获到变量中
我正在尝试关注 this example使用带有 remove_if 的 lambda。这是我的尝试: int flagId = _ChildToRemove->getId(); auto new_e
我无法捕获 在屏幕捕获区域内。 我想要一个定义的部分,其中包含要捕获的图像和内容。我们怎样才能做到这一点?帮助! 访问:https://stackblitz.com/edit/ngx-capture-
从 Perl 脚本调用外部程序时,Capture::Tiny 是否避免了使用 system() 时需要的磁盘 io?使用任何一种时,我都能获得基本相同的性能。一位同事正在使用我的代码并告诉我它正在敲打
作为数值方法研究的一部分,我正在编写一个函数来解决流值问题。这是该程序的“核心”,但它出现了一些奇怪的错误,这很奇怪,因为我在其他程序中使用了相同的代码段而没有出现任何错误。 void solve_
vector vec; //a auto foo = [&vec](){ //do something }; //b auto foo = [&v = vec](){ //do som
我正在使用 PyDev 对我的 Python 应用程序进行开发和单元测试。至于单元测试,除了没有内容被记录到日志框架之外,一切都很好。 PyDev 的“捕获的输出”没有捕获记录器。 我已经将记录的所有
你能帮我解决这个编译器错误吗? template static void ComputeGenericDropCount(function func) { T::ForEach([](T *w
第一次做泛型,我有点困惑。 我有以下内容: public interface GenericDao { /** * Retrieve an object that was previ
我正在尝试提取此代码中 dir_entry.path() 的值并想将其复制到 compFileName 中。问题是我一直收到错误“compFileName cannot be implicitly c
我正在使用在网上找到的 WebCam_Capture 代码通过 C# 访问网络摄像头。在一台只有一个视频源的计算机上,它就像一个魅力! (程序在启动时启动,找到网络摄像头并正常工作)。 虽然在一台有很
下面的代码 void CMainWindow::someMethod(const CLocationsCollection& parentItem) { auto f = [this, par
所以我打开了一个 youtube 页面,我可以在那里观看视频。 但是这个视频被用户下架了。我打开的页面仍然有视频,如果你再次访问(刷新)新页面没有。 由于我在浏览器选项卡 (chrome) 中加载了视
我是一名优秀的程序员,十分优秀!