Skip to content

Commit a6a630c

Browse files
committed
app lists first root component as 'index' in gatsby mode; fix issue where route links to index in gatsby and next modes did not function properly
1 parent 6473582 commit a6a630c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

app/src/helperFunctions/generateCode.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,12 @@ const generateUnformattedCode = (
119119
// route links are for gastby.js and next.js feature. if the user creates a route link and then switches projects, generate code for a normal link instead
120120
else if (child.type === 'Route Link') {
121121
if (projectType === 'Next.js') {
122-
return `<div><Link href="/${child.name}"><a>${child.name}</a></Link></div>`
122+
// if route link points to index, to go endpoint / rather than /index
123+
if (child.name === 'index') return `<div><Link href="/"><a>${child.name}</a></Link></div>`;
124+
else return `<div><Link href="/${child.name}"><a>${child.name}</a></Link></div>`;
123125
} else if (projectType === 'Gatsby.js') {
124-
return `<div><Link to="/${child.name}">${child.name}</Link></div>`
125-
// return `<div><Link href="/${child.name}"><a>${child.name}</a></Link></div>`
126+
if (child.name === 'index') return `<div><Link to="/">${child.name}</Link></div>`;
127+
else return `<div><Link to="/${child.name}">${child.name}</Link></div>`;
126128
} else return `<div><a>${child.name}</a></div>`
127129
}
128130
})

app/src/reducers/componentReducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ const reducer = (state: State, action: Action) => {
529529
});
530530

531531
// also update the name of the root component of the application to fit classic React and next.js conventions
532-
if (projectType === 'Next.js') components[0]['name'] = 'index';
532+
if (projectType === 'Next.js' || projectType === 'Gatsby.js') components[0]['name'] = 'index';
533533
else components[0]['name'] = 'App';
534534

535535
return { ...state, components, projectType };

0 commit comments

Comments
 (0)