Skip to content

Commit

Permalink
fix: giving different context to same layout don't work
Browse files Browse the repository at this point in the history
This is a ugly fix for this
ref: gatsbyjs/gatsby#3025
fixes #22
  • Loading branch information
abumalick committed Nov 25, 2017
1 parent 2d52cb4 commit 85c9d34
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
6 changes: 4 additions & 2 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ exports.createPages = ({graphql, boundActionCreators}) => {
}

const MainLayout = path.resolve(`./src/templates/MainLayout.jsx`)
const MainLayout2 = path.resolve(`./src/templates/MainLayout2.jsx`)

const homeTemplate = path.resolve(`./src/templates/Home.jsx`)
const sectionTemplate = path.resolve(`./src/templates/Section.jsx`)
Expand All @@ -51,9 +52,10 @@ exports.createPages = ({graphql, boundActionCreators}) => {
)

// layout for each lang
Object.keys(languagePaths).forEach((locale) => {
Object.keys(languagePaths).forEach((locale, i) => {
createLayout({
component: slash(MainLayout),
// component: slash(MainLayout),
component: slash(i === 1 ? MainLayout2 : MainLayout),
id: `main-layout-${locale}`,
context: {
languages,
Expand Down
51 changes: 51 additions & 0 deletions src/templates/MainLayout2.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// @flow
import * as React from 'react'
import 'antd/dist/antd.css'
import 'tachyons' // eslint-disable-line
import LanguagesNav from '../components/LanguagesNav'
import './styles.css'

type Props = {
children: Function,
location: {
// eslint-disable-line
pathname: string,
},
data: {
contentfulWebsite: {
languageChoiceLabel: string,
},
},
layoutContext: {
languages: Array<Object>,
locale: string,
},
location: {
pathname: string,
},
}
const MainLayout = ({children, data, layoutContext, location}: Props) => {
const {languageChoiceLabel} = data.contentfulWebsite
const {languages} = layoutContext
const {pathname} = location
return (
<div>
<LanguagesNav
languageChoiceLabel={languageChoiceLabel}
languages={languages}
pathname={pathname}
/>
{children()}
</div>
)
}

export default MainLayout

export const pageQuery = graphql`
query mainLayoutQuery2($locale: String!) {
contentfulWebsite(node_locale: {eq: $locale}) {
languageChoiceLabel
}
}
`

0 comments on commit 85c9d34

Please sign in to comment.