问题
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