Skip to content

Commit b5f86a2

Browse files
mraerinonickytonline
authored andcommitted
fix: produce a route for each locale
1 parent cac889c commit b5f86a2

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

packages/runtime/src/helpers/redirects.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ const generateStaticIsrRewrites = ({
162162
basePath,
163163
to: ODB_FUNCTION_PATH,
164164
force: true,
165+
// produce locale-specific routes
166+
i18n,
165167
}),
166168
)
167169
} else if (matchesMiddleware(middleware, route)) {

packages/runtime/src/helpers/utils.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,43 @@ export const redirectsForNextRouteWithData = ({
183183
to,
184184
status = 200,
185185
force = false,
186+
i18n,
186187
}: {
187188
route: string
188189
dataRoute: string
189190
basePath: string
190191
to: string
191192
status?: number
192193
force?: boolean
193-
}): NetlifyConfig['redirects'] =>
194-
generateNetlifyRoutes({ route, dataRoute, withData: true }).map((redirect) => ({
195-
from: `${basePath}${redirect}`,
196-
to,
197-
status,
198-
force,
199-
}))
194+
i18n?: I18n
195+
}): NetlifyConfig['redirects'] => {
196+
const paths = generateNetlifyRoutes({ route, dataRoute, withData: true })
197+
198+
const routes = []
199+
if (i18n?.locales?.length) {
200+
i18n.locales.flatMap((locale) =>
201+
paths.map((redirect) => ({
202+
from: `${basePath}${redirect}`,
203+
to,
204+
status,
205+
force,
206+
conditions: { Language: locale },
207+
})),
208+
)
209+
}
210+
211+
// rules without language condition
212+
routes.push(
213+
...paths.map((redirect) => ({
214+
from: `${basePath}${redirect}`,
215+
to,
216+
status,
217+
force,
218+
})),
219+
)
220+
221+
return routes
222+
}
200223

201224
export const getApiRewrites = (basePath: string, apiRoutes: Array<ApiRouteConfig>) => {
202225
const apiRewrites = apiRoutes.map((apiRoute) => {

0 commit comments

Comments
 (0)