我遇到了无法生成blog.js页面的问题。
成功
失败
我的部分解决方案(但不希望这样做)
・ Transfrer文件(./src/templates/blog.js)→(./src/pages/blog.js)可能显示页面(http:// localhost:8000 / blog ),但我不知道为什么),下面的错误消失了,但无法获取数据(有内容)。
错误
> warn The GraphQL query in the non-page component
> "C:/Users/taiga/Github/Gatsby-new-development-blog/my-blog/src/templates/blog.js"
> will not Exported queries are only executed for Page components. It's
> possible you're trying to create pages in your gatsby-node.js and
> that's failing for some reason.
>
> If the failing component(s) is a regular component and not intended to
> be a page component, you generally want to use a <StaticQuery>
> (https://gatsbyjs.org/docs/static-query) instead of exporting a page
> query.
下一个错误
答案 0 :(得分:1)
根据您的gatsby-node.js
,并假设您未注释这些行,则“阅读更多”按钮与生成所有t ech.js
内容的路径之间将不匹配。
首先,要澄清您的部分解决方案:它将永远不会起作用,因为在您的gatsby-node.js
中,您告诉盖茨比,所有contentfulBlog
的模板都是特定的模板。您正在根据检索到的数据生成每个页面,并在该模板中传递id
(以进行过滤)。由于您已将模板路径移至页面文件夹,因此所有内容均未正确传递并成为undefined
。
/blog/tech
未被设置为gatsby-node.js
中任何位置的路径。你有:
path: i === 0 ? `/category/tech` : `/category/tech/${i + 1}`,
因此,如果您的指向/blog/path
的“阅读更多”链接,则该链接将始终失败,因为可以正确获取该内容,但绝不会设置该路径。
您需要修复那些路径以适合您的要求。您可以将gatsby-node.js
path
更改为:
path: i === 0 ? `/blog/tech` : `/blog/tech/${i + 1}`,
或更改“阅读更多”按钮。