Skip to content

Commit 6837653

Browse files
committed
fix: locale splat for _next/static redirect
1 parent 06a5ae0 commit 6837653

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/helpers/config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const getNetlifyRoutes = (nextRoute) => {
5151
return netlifyRoutes
5252
}
5353

54-
exports.generateRedirects = async ({ netlifyConfig, basePath }) => {
54+
exports.generateRedirects = async ({ netlifyConfig, basePath, i18n }) => {
5555
const { dynamicRoutes } = await readJSON(join(netlifyConfig.build.publish, 'prerender-manifest.json'))
5656

5757
const redirects = []
@@ -76,9 +76,12 @@ exports.generateRedirects = async ({ netlifyConfig, basePath }) => {
7676
redirects.push(...getNetlifyRoutes(route), ...getNetlifyRoutes(dataRoute))
7777
})
7878

79+
// Needed only for /_next/static
80+
const i18nSplat = i18n ? '/:locale' : ''
81+
7982
// This is only used in prod, so dev uses `next dev` directly
8083
netlifyConfig.redirects.push(
81-
{ from: `${basePath}/_next/static/*`, to: '/static/:splat', status: 200 },
84+
{ from: `${basePath}${i18nSplat}/_next/static/*`, to: `${i18nSplat}/static/:splat`, status: 200 },
8285
{
8386
from: `${basePath}/*`,
8487
to: HANDLER_FUNCTION_PATH,
@@ -119,7 +122,6 @@ exports.setIncludedFiles = ({ netlifyConfig, publish }) => {
119122
netlifyConfig.functions[functionName].included_files.push(
120123
`${publish}/server/**`,
121124
`${publish}/serverless/**`,
122-
`${publish}/static/**`,
123125
`${publish}/*.json`,
124126
`${publish}/BUILD_ID`,
125127
)

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = {
4242

4343
checkNextSiteHasBuilt({ publish, failBuild })
4444

45-
const { images, target, appDir, basePath } = await getNextConfig({ publish, failBuild })
45+
const { appDir, basePath, i18n, images, target } = await getNextConfig({ publish, failBuild })
4646

4747
setBundler({ netlifyConfig, target })
4848

@@ -59,6 +59,7 @@ module.exports = {
5959
await generateRedirects({
6060
netlifyConfig,
6161
basePath,
62+
i18n,
6263
})
6364
},
6465

0 commit comments

Comments
 (0)