From 82eb8f050e6ea504bf4c4fb2308fbe5781f0b288 Mon Sep 17 00:00:00 2001 From: Birkir Gudjonsson Date: Wed, 27 Mar 2019 10:56:22 -0400 Subject: [PATCH] fix: ensure location is in props --- .../src/components/WrapPage.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/gatsby-source-prismic-graphql/src/components/WrapPage.tsx b/packages/gatsby-source-prismic-graphql/src/components/WrapPage.tsx index 27e1906f3..0034baaaf 100644 --- a/packages/gatsby-source-prismic-graphql/src/components/WrapPage.tsx +++ b/packages/gatsby-source-prismic-graphql/src/components/WrapPage.tsx @@ -1,5 +1,5 @@ import { getIsolatedQuery } from 'gatsby-source-graphql-universal'; -import { pick } from 'lodash'; +import { pick, get } from 'lodash'; import pathToRegexp from 'path-to-regexp'; import Prismic from 'prismic-javascript'; import React from 'react'; @@ -36,8 +36,8 @@ export class WrapPage extends React.PureComponent { const params: any = { ...this.props.pageContext }; const keys: any = []; - const re = pathToRegexp(this.props.pageContext.matchPath || '', keys); - const match = re.exec(this.props.location.pathname); + const re = pathToRegexp(get(this.props.pageContext, 'matchPath', ''), keys); + const match = re.exec(get(this.props, 'location.pathname', '')); if (match) { keys.forEach((value: any, index: number) => { if (!params[value.name]) { @@ -46,7 +46,7 @@ export class WrapPage extends React.PureComponent { }); } - const qs = parseQueryString(String(this.props.location.search).substr(1)); + const qs = parseQueryString(String(get(this.props, 'location.search', '?')).substr(1)); this.keys.forEach((key: string) => { if (!params[key] && qs.has(key)) { params[key] = qs.get(key); @@ -58,7 +58,7 @@ export class WrapPage extends React.PureComponent { getQuery() { const child = this.props.children as any; - let query = queryOrSource(this.props.pageContext.rootQuery) || ''; + let query = queryOrSource(get(this.props.pageContext, 'rootQuery')) || ''; if (child && child.type) { if (child.type.query) {