Skip to content

Commit

Permalink
fix infinite redirect on root path
Browse files Browse the repository at this point in the history
  • Loading branch information
rtrembecky committed Dec 17, 2024
1 parent 52a33b8 commit 84231e9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 84231e9

Please sign in to comment.