Skip to content

Commit cebe8d8

Browse files
authored
fix: redirect named splat filesystem routes correctly for SSR/DSG pages (#120)
* fix: ignore named splats when writing redirects * fix: make ssr/dsg and client-only redirects mutually exclusive * fix: handle undefined matchpath
1 parent 938a0f2 commit cebe8d8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/gatsby-node.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ export const onPostBuild = async ({ store, pathPrefix, reporter }: any, userPlug
7676

7777
;[...pages.values()].forEach((page) => {
7878
const { mode, matchPath, path } = page
79+
const matchPathClean = matchPath && matchPath.replace(/\*.*/, '*')
80+
const matchPathIsNotPath = matchPath && matchPath !== path
81+
7982
if (mode === `SSR` || mode === `DSG`) {
8083
needsFunctions = true
81-
const fromPath = matchPath ?? path
84+
const fromPath = matchPathClean ?? path
8285
const toPath = mode === `SSR` ? `/.netlify/functions/__ssr` : `/.netlify/functions/__dsg`
8386
count++
8487
rewrites.push(
@@ -91,10 +94,9 @@ export const onPostBuild = async ({ store, pathPrefix, reporter }: any, userPlug
9194
toPath,
9295
},
9396
)
94-
}
95-
if (pluginOptions.generateMatchPathRewrites && matchPath && matchPath !== path) {
97+
} else if (pluginOptions.generateMatchPathRewrites && matchPathIsNotPath) {
9698
rewrites.push({
97-
fromPath: matchPath,
99+
fromPath: matchPathClean,
98100
toPath: path,
99101
})
100102
}

0 commit comments

Comments
 (0)