Skip to content

Commit ebcd2e5

Browse files
committed
Skip prerendered routes in i18n middleware
1 parent a3f4f6c commit ebcd2e5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/middlewares/i18n-redirect.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ export default defineMiddleware((ctx, next) => {
7474
const url = new URL(ctx.request.url);
7575
const pathname = url.pathname;
7676

77-
console.log("i18n-redirect middleware:");
78-
console.log(" -- isPrerendered:", ctx.isPrerendered);
77+
console.log("i18n-redirect middleware:", pathname, ctx.isPrerendered);
78+
79+
// Skip prerendered pages, since they are static and don't have access to request headers & cookies.
80+
// But when this middleware is deployed as edge middleware to Vercel, ctx.isPrerendered is always false.
81+
if (ctx.isPrerendered) {
82+
return next();
83+
}
7984

8085
if (!(i18MatcherRegexp as unknown as RegExp).test(pathname)) {
8186
return next();

0 commit comments

Comments
 (0)