Skip to content

Commit 7d01aba

Browse files
fix: basePath is undefined when a site has no config file (#385)
1 parent dd15c66 commit 7d01aba

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/lib/helpers/convertToBasePathRedirects.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// NOTE: /withoutProps/redirects.js has some of its own contained basePath logic
44

55
const getBasePathDefaultRedirects = ({ basePath, nextRedirects }) => {
6-
if (basePath === '') return []
6+
if (!basePath) return []
77
// In a basePath-configured site, all _next assets are fetched with the prepended basePath
88
return [
99
{
@@ -16,7 +16,7 @@ const getBasePathDefaultRedirects = ({ basePath, nextRedirects }) => {
1616
}
1717

1818
const convertToBasePathRedirects = ({ basePath, nextRedirects }) => {
19-
if (basePath === '') return nextRedirects
19+
if (!basePath) return nextRedirects
2020
const basePathRedirects = getBasePathDefaultRedirects({ basePath, nextRedirects })
2121
nextRedirects.forEach((r) => {
2222
if (r.route === '/') {

src/lib/helpers/formatRedirectTarget.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const { DYNAMIC_PARAMETER_REGEX } = require('../constants/regex')
33

44
const formatRedirectTarget = ({ basePath, target }) =>
5-
basePath !== '' && target.includes(basePath)
5+
basePath && basePath !== '' && target.includes(basePath)
66
? target.replace(DYNAMIC_PARAMETER_REGEX, '/:$1').replace('[', '').replace(']', '').replace('...', '')
77
: target
88

src/lib/pages/withoutProps/redirects.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const getRedirects = async () => {
3030

3131
// For sites that use basePath, manually add necessary redirects here specific
3232
// only to this page type (which excludes static route redirects by default)
33-
if (basePath !== '') {
33+
if (basePath && basePath !== '') {
3434
redirects.push({
3535
route: `${basePath}${route}`,
3636
target: route,

src/lib/steps/setupRedirects.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const setupRedirects = async (publishPath) => {
4848
redirects.push('# Next-on-Netlify Redirects')
4949

5050
const { basePath } = await getNextConfig()
51-
if (basePath !== '') {
51+
if (basePath && basePath !== '') {
5252
nextRedirects = convertToBasePathRedirects({ basePath, nextRedirects })
5353
}
5454

0 commit comments

Comments
 (0)