Next.js Discord

Discord Forum

Middleware redirect loop when following documentation

Unanswered
Rex posted this in #help-forum
Open in Discord
RexOP
hi,

I need to handle trailing slash conditionally and was following https://nextjs.org/docs/app/building-your-application/routing/middleware#advanced-middleware-flags but it seems that the redirects stuck in a loop when accessing any route (for example /mislav). Here's codesandbox of descibed behaviour: https://codesandbox.io/p/live/87e96883-2418-4789-83cb-4a479ea874fa?file=%2Fmiddleware.ts%3A1%2C22.

If any of you know what is happening here or how to resolve this to append trailing slash to every route except those with legacyPrefixes I would be very thankful.

0 Replies