Skip to content

Commit 52ee02c

Browse files
committed
chore: refactor hidden path redirects
1 parent 0996adc commit 52ee02c

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

packages/runtime/src/helpers/redirects.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ import {
2323
const matchesMiddleware = (middleware: Array<string>, route: string): boolean =>
2424
middleware.some((middlewarePath) => route.startsWith(middlewarePath))
2525

26+
const generateHiddenPathRedirects = ({ basePath }: Pick<NextConfig, 'basePath'>): NetlifyConfig['redirects'] =>
27+
HIDDEN_PATHS.map((path) => ({
28+
from: `${basePath}${path}`,
29+
to: '/404.html',
30+
status: 404,
31+
force: true,
32+
}))
33+
2634
const generateLocaleRedirects = ({
2735
i18n,
2836
basePath,
@@ -262,21 +270,12 @@ export const generateRedirects = async ({
262270
join(netlifyConfig.build.publish, 'routes-manifest.json'),
263271
)
264272

265-
netlifyConfig.redirects.push(
266-
...HIDDEN_PATHS.map((path) => ({
267-
from: `${basePath}${path}`,
268-
to: '/404.html',
269-
status: 404,
270-
force: true,
271-
})),
272-
)
273+
netlifyConfig.redirects.push(...generateHiddenPathRedirects({ basePath }))
273274

274275
if (i18n && i18n.localeDetection !== false) {
275276
netlifyConfig.redirects.push(...generateLocaleRedirects({ i18n, basePath, trailingSlash }))
276277
}
277278

278-
netlifyConfig.redirects.push(...generateCustom404Redirects({ i18n }))
279-
280279
// This is only used in prod, so dev uses `next dev` directly
281280
netlifyConfig.redirects.push(
282281
// API routes always need to be served from the regular function

0 commit comments

Comments
 (0)