From 84231e9885b4b4c21d8f91d00de0ed2f3ac8e8a2 Mon Sep 17 00:00:00 2001 From: rtrembecky Date: Tue, 17 Dec 2024 20:26:03 +0100 Subject: [PATCH] fix infinite redirect on root path --- src/middleware.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/middleware.ts b/src/middleware.ts index 6c63459e..14af30b6 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -13,7 +13,8 @@ export function middleware(req: NextRequest) { // odstran trailing slash - default next.js spravanie, ale vypli sme ho v next.config.ts pomocou // `skipTrailingSlashRedirect: true`, aby sme dovolili (a v axiose a middlewari vyssie aj forcli) // trailing slash pre BE Django - if (url.pathname.endsWith('/')) { + // pre root route `/` to nemozeme spravit (infinite redirect) ¯\_(ツ)_/¯ + if (url.pathname.endsWith('/') && url.pathname !== '/') { const newPathname = url.pathname.slice(0, -1) const newUrl = new URL(`${newPathname}${url.search}`, url)