From ae91ff60998f56ee7725a4744da744a0b821b655 Mon Sep 17 00:00:00 2001 From: Ben McCormick Date: Tue, 25 Jul 2017 16:01:12 -0400 Subject: [PATCH] Gatsby-link: Don't assume that __PREFIX_PATH__ is defined --- packages/gatsby-link/src/__tests__/index.js | 8 ++++++++ packages/gatsby-link/src/index.js | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-link/src/__tests__/index.js b/packages/gatsby-link/src/__tests__/index.js index 1aa1e376f46e5..638ea94fea49c 100644 --- a/packages/gatsby-link/src/__tests__/index.js +++ b/packages/gatsby-link/src/__tests__/index.js @@ -19,6 +19,14 @@ const getNavigateTo = () => { } describe(``, () => { + + it(`does not fail to initialize when __PREFIX_PATHS__ is not defined`, () => { + expect(() => { + const Link = require(`../`).default + const link = new Link({}) //eslint-disable-line no-unused-vars + }).not.toThrow() + }) + describe(`path prefixing`, () => { it(`does not include path prefix by default`, () => { const to = `/path` diff --git a/packages/gatsby-link/src/index.js b/packages/gatsby-link/src/index.js index 7e9fc7f89e39f..39864303f1628 100644 --- a/packages/gatsby-link/src/index.js +++ b/packages/gatsby-link/src/index.js @@ -1,9 +1,10 @@ +/*global __PREFIX_PATHS__, __PATH_PREFIX__ */ import React from "react" import { Link, NavLink } from "react-router-dom" import PropTypes from "prop-types" let pathPrefix = `` -if (__PREFIX_PATHS__) { +if (typeof __PREFIX_PATHS__ !== `undefined` && __PREFIX_PATHS__) { pathPrefix = __PATH_PREFIX__ }