Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
fix: ensure location is in props
Browse files Browse the repository at this point in the history
  • Loading branch information
birkir committed Mar 27, 2019
1 parent 8d00d4b commit 82eb8f0
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -36,8 +36,8 @@ export class WrapPage extends React.PureComponent<any, WrapPageState> {
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]) {
Expand All @@ -46,7 +46,7 @@ export class WrapPage extends React.PureComponent<any, WrapPageState> {
});
}

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);
Expand All @@ -58,7 +58,7 @@ export class WrapPage extends React.PureComponent<any, WrapPageState> {

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) {
Expand Down

0 comments on commit 82eb8f0

Please sign in to comment.