如何设置来自 Drupal 的主页 / Gatsby 中的 /home

问题描述 投票:0回答:1

我正在使用 Drupal CMS 作为后端创建一个 Gatsby 网站。我在 Drupal 中有登陆页面内容类型,它提供主页和关于我们的页面。现在Drupal主页路径是/home。但 Gatsby 有主页 URL '/'。从 Drupal 提取数据后,Gatsby 认为 /home 是单独的页面而不是索引页面。

我尝试在 Gatsby 节点 js 文件上的 CreatePage API 中设置路径。但没有成功。

drupal gatsby
1个回答
0
投票

她是我的发现,

  • 删除Gatsby中的index.js文件
  • 确保 Drupal 主页为 URL 别名为 /home。
  • 转到 Gatsby-node.js 文件并将 slug 更改为“/” 在调用 CreatePage 之前从 '/home/' 开始,如下所示
  • 注意:Context slug 应保留 /home/,因此请勿更改该值。

  result.data.allNodeLanding.edges.forEach(({ node }) => {
    const slug = node.fields.slug;
    if (node.fields.slug === '/home/') {
      node.fields.slug = '/'
    }
    actions.createPage({
      path: node.fields.slug,
      component: tpl,
      context: {
        slug: slug
      }
    });
  });

© www.soinside.com 2019 - 2024. All rights reserved.