通过Gatsby createPages节点api创建的页面,在部署到Github Pages时不起作用



我正在使用Gatsby createPages节点api创建一些页面,如下所述:https://www.gatsbyjs.com/docs/programmatically-create-pages-from-data/#creating-页面

但是当我部署到github页面时,这些页面会给出404,例如这个页面:https://giorgioremindme.github.io/probable-future

这就是我在gatsby节点js:中的内容

const fs = require(`fs`)
const yaml = require(`js-yaml`)
exports.createPages = ({ actions }) => {
const { createPage } = actions
const ymlDoc = yaml.safeLoad(fs.readFileSync(`./src/content/index.yaml`, `utf-8`))
ymlDoc.forEach(element => {
createPage({
path: element.path,
component: require.resolve(`./src/templates/basicTemplate.js`),
context: {
pageContent: element.content,
links: element.links,
},
})
})
}

https://github.com/GiorgioRemindme/giorgio-martini/blob/main/gatsby-node.js

不过本地运行良好。。。

您可以通过单击在此页面上看到的缩略图来访问这些新页面:https://giorgioremindme.github.io/giorgio-martini/code忽略最后一个缩略图,该缩略图已损坏,缺少有效链接,但其余缩略图在本地工作,但未部署。

有什么想法我需要做什么,使这个页面在部署时工作?

如果输入:https://giorgioremindme.github.io/giorgio-martini/code(没有尾部斜杠。您可以通过单击标题中的"代码"链接将其删除(。

然后你导航,网站工作顺利,没有404返回。

但是,如果您输入https://giorgioremindme.github.io/giorgio-martini/code/(注意后面的斜线(,当您的页面试图导航到它们时,会返回404。

您的gatsby-node.js没有任何问题,因为页面是正确创建的,并且它们是存在的。你的问题在你的应用内链接/导航中,也在视图中。

尽管如此,我的猜测是,您正在手动为路径添加前缀,直接添加/code,而Gatsby链接应该自己完成。手动构建链接时,请尝试使用withPrefix助手。

仔细检查此行为和本地构建,以确定问题的来源在哪里(本地或GitHub的环境中(,因为解决方案可能会因情况而异。

最新更新