Skip to content

fix: basePath is undefined when a site has no config file #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/helpers/convertToBasePathRedirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
{
Expand All @@ -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 === '/') {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/formatRedirectTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/lib/pages/withoutProps/redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/steps/setupRedirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}

Expand Down