我正在通過 Contentful 構建一個具有多種語言的動態 Gatsby 網站。pageContext我在我的對象中傳遞頁面的 IDgatsby-node.js以獲取每個頁面上的必要內容,但在根 URL 上/,我的pageContext對象內的數據丟失了。在我的index.js-file 中,pageContext根頁面上的 是空的/,但參數pageContext.isCreatedByStatefulCreatePages設置為true. 但是,對于在對象中創建的每個其他頁面gatsby-node.js,pageContext它都會按原樣顯示。我正在gatsby-node.js這樣創建我的頁面:const baseUrl = locale === "da" ? "/" : `/${locale}/`console.log(`${baseUrl}${slug ? slug : ""}`)createPage({ path: `${baseUrl}${slug ? slug : ""}`, component: path.resolve("./src/pages/index.js"), context: { id, slug, locale, },})我上面console.log的輸出如下:/virksomhed/konsulent/kontakt/ <-- Page context is empty here/om-os/en/company/en/consultant/en/contact/en//en/about-us我可以看到每個頁面都已創建。在索引頁面 ("/") 以外的任何其他頁面上,isCreatedByStatefulCreatePages 設置為false。我懷疑 Gatsby 以某種方式覆蓋了根 URL 的“createPage”,但我無法在文檔中找到任何描述它的內容。有這方面經驗的人嗎?
Gatsby pageContext 在 GraphQL 中為空
三國紛爭
2022-01-13 15:24:03