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__ }