javascript - 设置 Gatsby 博客分层 URL slug 结构

标签 javascript html url hyperlink gatsby

我目前正在使用 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 和 Web 开发对我来说都是相当新的。

最佳答案

您需要更改 this line

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

关于javascript - 设置 Gatsby 博客分层 URL slug 结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58266510/

相关文章:

javascript - 为什么我正在加载的图像丢失了?

javascript - 如何从一个html链接并显示第二个html中存在的多个div的单个div?

javascript - 在 URL 中传递一个包含 '%' 的参数?

javascript - 使用 Connect 进行 mapStateToProps 和 mapDispatchToProps 时对 redux : still getting empty object for this. props 使用react

javascript - Konva.js 中是否可以用鼠标左键绘制并用鼠标右键拖动舞台?

javascript - 将 <div> 元素内的数字输入转换为人类可读的日期

javascript - 隐藏按钮直到满足条件(Javascript)

javascript - 检查并仅用 javascript 替换 div 字符串

python - BeautifulSoup 只返回 head 标签内的内容

php - 如何获取没有模式且以 php 结尾的 URL 主机?