The right way to define a sourced page as Gatsby's front page

Deadly 提交于 2020-01-15 11:28:26

问题


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 /?

Thanks in advance.


回答1:


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"),
  })

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.



来源:https://stackoverflow.com/questions/59721965/the-right-way-to-define-a-sourced-page-as-gatsbys-front-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!