将源页面定义为盖茨比首页的正确方法 [英] The right way to define a sourced page as Gatsby's front page
问题描述
我从Wordpress实例创建了一个Gatsby/React实例源.我基于从Wordpress中获取的页面对象生成页面.一切正常.我知道我必须将路由/
的内容放入src/pages/index.js
.将我的来源网页路由之一(例如/start
)定义为/
的正确/规范方法是什么?
I created a Gatsby/React instance sourcing from a Wordpress instance. I generate pages based on the page objects that I source from Wordpress. Everything works fine. I know that I have to put my content for the route /
into src/pages/index.js
. What would be the correct/canonical way to define one of my sourced page routes e.g./start
as /
?
先谢谢了.
推荐答案
基本上,您只需在路径设置为/
的情况下调用createPage
.在CMS中如何处理此问题实际上取决于您设置的结构.
Basically you just call createPage
with the path set to /
. How you handle this in your CMS really depends on the structure you've set.
exports.createPages = ({ actions }) =>
actions.createPage({
path: "/",
component: path.resolve("./src/templates/some_template.jsx"),
})
我倾向于在CMS中对子段(例如/about/
)要求在斜杠前面和后面加上斜杠,这使内容编辑器可以轻松地将/
留给注定要成为主页的页面/root页面.过去,我还使用home
作为魔术值,该值会在gatsby-node.js
中转换为/
,但会引起混乱.
I tend to prefer to require preceding and trailing slashes on slugs (e.g. /about/
) in the CMS, which makes it easy to allow a content editor to leave just /
for a page that is destined to become the home/root page. In the past I've also used home
as a magic value that would be converted to /
in gatsby-node.js
, but it can cause confusion.
这篇关于将源页面定义为盖茨比首页的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!