From 1587af8261da732b05827c78d2da82ddbd021ece Mon Sep 17 00:00:00 2001 From: Lindsay Levine Date: Fri, 4 Jun 2021 04:10:10 -0400 Subject: [PATCH] fix: basePath is undefined when a site has no config file --- src/lib/helpers/convertToBasePathRedirects.js | 4 ++-- src/lib/helpers/formatRedirectTarget.js | 2 +- src/lib/pages/withoutProps/redirects.js | 2 +- src/lib/steps/setupRedirects.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/helpers/convertToBasePathRedirects.js b/src/lib/helpers/convertToBasePathRedirects.js index e154bb8f53..f7d380228d 100644 --- a/src/lib/helpers/convertToBasePathRedirects.js +++ b/src/lib/helpers/convertToBasePathRedirects.js @@ -3,7 +3,7 @@ // NOTE: /withoutProps/redirects.js has some of its own contained basePath logic const getBasePathDefaultRedirects = ({ basePath, nextRedirects }) => { - if (basePath === '') return [] + if (!basePath) return [] // In a basePath-configured site, all _next assets are fetched with the prepended basePath return [ { @@ -16,7 +16,7 @@ const getBasePathDefaultRedirects = ({ basePath, nextRedirects }) => { } const convertToBasePathRedirects = ({ basePath, nextRedirects }) => { - if (basePath === '') return nextRedirects + if (!basePath) return nextRedirects const basePathRedirects = getBasePathDefaultRedirects({ basePath, nextRedirects }) nextRedirects.forEach((r) => { if (r.route === '/') { diff --git a/src/lib/helpers/formatRedirectTarget.js b/src/lib/helpers/formatRedirectTarget.js index ed8d3c7c09..7504b96a9d 100644 --- a/src/lib/helpers/formatRedirectTarget.js +++ b/src/lib/helpers/formatRedirectTarget.js @@ -2,7 +2,7 @@ const { DYNAMIC_PARAMETER_REGEX } = require('../constants/regex') const formatRedirectTarget = ({ basePath, target }) => - basePath !== '' && target.includes(basePath) + basePath && basePath !== '' && target.includes(basePath) ? target.replace(DYNAMIC_PARAMETER_REGEX, '/:$1').replace('[', '').replace(']', '').replace('...', '') : target diff --git a/src/lib/pages/withoutProps/redirects.js b/src/lib/pages/withoutProps/redirects.js index b85eafb6b3..25b48b4bb2 100644 --- a/src/lib/pages/withoutProps/redirects.js +++ b/src/lib/pages/withoutProps/redirects.js @@ -30,7 +30,7 @@ const getRedirects = async () => { // For sites that use basePath, manually add necessary redirects here specific // only to this page type (which excludes static route redirects by default) - if (basePath !== '') { + if (basePath && basePath !== '') { redirects.push({ route: `${basePath}${route}`, target: route, diff --git a/src/lib/steps/setupRedirects.js b/src/lib/steps/setupRedirects.js index 50ff238d09..b7fface5b0 100644 --- a/src/lib/steps/setupRedirects.js +++ b/src/lib/steps/setupRedirects.js @@ -48,7 +48,7 @@ const setupRedirects = async (publishPath) => { redirects.push('# Next-on-Netlify Redirects') const { basePath } = await getNextConfig() - if (basePath !== '') { + if (basePath && basePath !== '') { nextRedirects = convertToBasePathRedirects({ basePath, nextRedirects }) }