【发布时间】:2020-09-14 19:48:44
【问题描述】:
我正在构建一个 Gatsby + Contentful 博客,并且在开发中一切正常。但是当我构建页面时,它会显示整个网站两次。
一切都应该在<div id="___gatsby"></div> 中。但它也会在<div id="___gatsby"></div> 之外再次呈现<main> 和<footer>(整个网站)
这是一张图片: gatsby renders entire website twice
我的 Layout.js 有问题吗?
Layout.js
import React from 'react'
import Navbar from './Navbar'
import BeforeFooter from './BeforeFooter'
import Footer from './Footer'
const Layout = ({ children }) => {
return (
<>
<Navbar />
<main>{children}</main>
<BeforeFooter />
<Footer />
</>
)
}
export default Layout
或者它可能是导致错误的插件?
gatsby-config.js
require("dotenv").config({
path: `.env.${process.env.NODE_ENV}`,
})
module.exports = {
siteMetadata: {
title: `Gatsby Contentful Blog`,
description: `Awesome Blog built with Gatsby and Contentful`,
titleTemplate: `%s Contentful Blog`,
url: `https://mdx-blog.netlify.app/`,
image: `mainImg.png`,
twitterUsername: `@john`,
},
plugins: [
`gatsby-plugin-react-helmet`,
`gatsby-plugin-styled-components`,
`gatsby-remark-images`,
`gatsby-plugin-sass`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `assets`,
path: `${__dirname}/src/assets`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `posts`,
path: `${__dirname}/src/images`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-source-contentful`,
options: {
spaceId: ``,
// Learn about environment variables: https://gatsby.dev/env-vars
accessToken: ``,
forceFullSync: true,
},
},
{
resolve: `gatsby-plugin-prefetch-google-fonts`,
options: {
fonts: [
{
family: `Roboto`,
variants: [`400`, `500`, `700`],
},
{
family: `Open Sans`,
},
{
family: `Teko`,
},
],
},
},
{
resolve: `gatsby-plugin-gdpr-cookies`,
options: {
googleAnalytics: {
trackingId: 'YOUR_GOOGLE_ANALYTICS_TRACKING_ID',
// Setting this parameter is optional
anonymize: true
},
facebookPixel: {
pixelId: 'YOUR_FACEBOOK_PIXEL_ID'
},
// Defines the environments where the tracking should be available - default is ["production"]
environments: ['production', 'development']
},
},
],
}
我对这个堆栈非常陌生,我无法理解我做错了什么......让我知道你们是否可以帮助我或需要查看我的更多代码来提供帮助。
有人知道这是否是一个实际的布局问题吗?
【问题讨论】:
-
您是否在
NavBar、BeforeFooter或Footer中使用<Layout>组件? -
您好,感谢您的回复 :) 您的意思是我在 Navbar、BeforeFooter 或 Footer 中导入布局组件?
-
正是这个。我想知道你是否在那里导入
<Layout>组件。
标签: reactjs gatsby contentful