我目前正在使用 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/