简体   繁体   English

React SPA-显示加载屏幕,直到呈现多个组件

[英]React SPA - Show loading screen until multiple components are rendered

Apologies for the relatively conceptual question. 对于相对概念性的问题表示歉意。 I'm attempting to emulate the full-page Heroku loading screen that appears when the page first loads and disappears after the navbar, images, libraries, and other components have mounted: 我正在尝试模拟整页Heroku加载屏幕,该页面在页面第一次加载时出现,在导航栏,图像,库和其他组件已安装后消失:

Heroku加载截图

I know the underlying stack of Heroku is Ember , but is there a good practice/way for accomplishing a similar effect using node.js , webpack , react , react-router , and express . 我知道Heroku的基础堆栈是Ember ,但是有一个好的实践/方法来使用node.jswebpackreactreact-routerexpress实现类似的效果。 It's not isomorphic and I would prefer all rendering to take place on the client. 它不是同构的,我希望所有渲染都在客户端上进行。

Thank you for your help and let me know if there's any other information that would be helpful in understanding what I'm trying to do. 感谢您的帮助,如果您还有其他信息可以帮助您理解我的工作,请告诉我。

I haven't tried this but I imagine you could simply provide the HTML for your 'full page loading screen' as the initial HTML that comes with your page, and then simply replace it with your ReactDOM.render call which will only get processed after everything has been processed. 我还没有尝试过,但是我想您可以简单地为“全页加载屏幕”提供HTML,作为页面随附的初始HTML,然后简单地将其替换为ReactDOM.render调用,该调用将在处理后一切都已处理。

More specifically, if you put all of your JS script tags in the footer, then the rest of your document will load and render while the scripts are being loaded, giving you your 'loading screen' effect. 更具体地说,如果将所有JS脚本标记放在页脚中,则在加载脚本时将加载并呈现文档的其余部分,从而获得“加载屏幕”的效果。 It should work to simply put the loading graphic within a div and then render over it with React. 它应该可以简单地将加载图形放在div中,然后使用React对其进行渲染。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM