Gatsby如何在React组件和先前生成的静态HTML内容之间共享React标头 [英] Gatsby how to share React header between React components and previously generated static HTML content

查看:64
本文介绍了Gatsby如何在React组件和先前生成的静态HTML内容之间共享React标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个盖茨比站点.该站点由多个React页面组件"组成,所有这些都包裹在React标头组件和React页脚组件中.

I am building a Gatsby site. The site consists of multiple React "page-components", all of which get wrapped in a React header component and a React footer component.

我有一些预先存在的静态HTML(例如隐私权政策& c"之类的东西).我打算将它们发布在/public gatsby文件夹中.但是那样就不会有React的header组件和footer组件.

I have some pre-existing static HTML (think things like Privacy Policy &c). I was planning to just publish them in the /public gatsby folder. But then the won't have the React header component and footer component.

如何发布静态HTML内容并为它们提供React页眉/页脚?

How can I publish my static HTML content AND give them the React header/footer?

我想像一下,如果我将静态HTML转换"为JSX,那么当然可以.只是想了解这是否是唯一的方法,正确的方法,或者是否有更简单的方法?

I imagine that if I "translate" my static HTML to JSX then of course that would work. Just want to understand if that is the only way, the right way, or whether there is an easier way?

推荐答案

Gatsby将在构建时为您创建静态公共文件(我建议使用Netlify).您应该应该"在页面文件夹或components文件夹中创建react组件,这意味着要使用JSX.标头实际上已经是布局文件夹的一部分,因此您无需为此做任何事情.

Gatsby will create the static public files for you at build time (I recommend Netlify). You 'should' be creating react components which means using JSX, either in the pages folder or the components folder. The header is actually already part of the layouts folder so you don't have to do anything on that count.

根据我的理解,如果您只是创建新的页面文件或修改现有的页面文件以显示您的内容,那么您将得到想要的行为.然后,您可以根据自己的喜好自定义事物,即页面,标题内容和样式.

Based on what I am understanding, if you just create new page files or modify the existing page files to display your content you will get the behaviour you're after. Then it's just a matter of customizing things i.e. the pages and the header content and styles, to your liking.

这篇关于Gatsby如何在React组件和先前生成的静态HTML内容之间共享React标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆