Skip to content

fix: redirect named splat filesystem routes correctly for SSR/DSG pages #120

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 3 commits into from
Apr 27, 2022
Merged
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
10 changes: 6 additions & 4 deletions src/gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ export const onPostBuild = async ({ store, pathPrefix, reporter }: any, userPlug

;[...pages.values()].forEach((page) => {
const { mode, matchPath, path } = page
const matchPathClean = matchPath && matchPath.replace(/\*.*/, '*')
const matchPathIsNotPath = matchPath && matchPath !== path

if (mode === `SSR` || mode === `DSG`) {
needsFunctions = true
const fromPath = matchPath ?? path
const fromPath = matchPathClean ?? path
const toPath = mode === `SSR` ? `/.netlify/functions/__ssr` : `/.netlify/functions/__dsg`
count++
rewrites.push(
Expand All @@ -91,10 +94,9 @@ export const onPostBuild = async ({ store, pathPrefix, reporter }: any, userPlug
toPath,
},
)
}
if (pluginOptions.generateMatchPathRewrites && matchPath && matchPath !== path) {
} else if (pluginOptions.generateMatchPathRewrites && matchPathIsNotPath) {
rewrites.push({
fromPath: matchPath,
fromPath: matchPathClean,
toPath: path,
})
}
Expand Down