【问题标题】:Setting up Gatsby blog hierarchical URL slug structure设置 Gatsby 博客分层 URL slug 结构
【发布时间】:2020-02-04 13:40:09
【问题描述】:

我目前正在使用 Gatsby Starter 博客 (https://github.com/gatsbyjs/gatsby-starter-blog) - 我可以毫无问题地在本地运行它。

但是我想更改 URL 结构 -

目前,如果我发表一篇名为“hello world”的博文,那么 URL 将是“www.example/hello-world”。我希望 URL 采用“www.example/blog/hello-world”的形式。

我看过一些关于在 gatsby-node.js 中更改设置的帖子,但没有具体解决我的问题。我不清楚我需要更改什么,因为 Gatsby 链接 API 和网络开发对我来说都是相当新的。

【问题讨论】:

  • 我建议您遵循以下内容:link。这个视频正是你想要的。工作示例在这里:link.
  • 多亏看了那段视频,我确实开始工作了 - 谢谢!
  • 供跟踪的人将来参考 - 将 path: post.node.fields.slug 更改为 path: ``/blog${post.node.fields.slug}

标签: javascript html url hyperlink gatsby


【解决方案1】:

您需要更改this line

    createPage({
      path: `/blog${node.fields.slug}`, // this line
      component: blogPost,
      context: {
        slug: post.node.fields.slug,
        previous,
        next,
      },
    })

【讨论】:

  • 谢谢 - 我意识到它还需要在其他几个地方进行更改,但这是我正在寻找的格式。解决了。​​
  • 这是一个很好的问题 - 我不记得了,但我会看看
猜你喜欢
  • 2021-04-17
  • 2012-06-10
  • 2023-03-18
  • 2020-07-16
  • 1970-01-01
  • 2020-05-31
  • 2021-07-14
  • 2011-10-05
  • 2017-09-09
相关资源
最近更新 更多