QuiiBz / next-international

Type-safe internationalization (i18n) for Next.js
https://next-international.vercel.app
MIT License
1.2k stars 54 forks source link

Redirections to /api #303

Closed Eusebiotrigo closed 7 months ago

Eusebiotrigo commented 7 months ago

It is more a question than a bug.

How do we handle in the middleware that the requests to "/api" are not prefixed with the locale?

Thanks!

Eusebiotrigo commented 7 months ago

I'll answer myself:

Having:

export function middleware(request: NextRequest) {
  return I18nMiddleware(request);
}

Do your thing in

export function middleware(request: NextRequest) {
  const { pathname } = req.nextUrl;

    if (pahtName.contains("YOUR PUBLIC OR /api") return;
  return I18nMiddleware(request);
}