import { NextResponse } from 'next/server'; import createMiddleware from 'next-intl/middleware'; import { routing } from '@/i18n/routing'; const middleware = createMiddleware(routing); export default function handler(req) { const { pathname, search } = req.nextUrl; const locale = pathname.split('/')[1]; // Obtenez la locale actuelle // Vérifiez si la route ne contient pas de locale if (!pathname.startsWith('/fr') && !pathname.startsWith('/en')) { // Redirigez vers la locale par défaut (fr) avec les paramètres de recherche console.log('Redirecting to /fr'); return NextResponse.redirect(new URL(`/fr${pathname}${search}`, req.url)); } return middleware(req); } export const config = { // Match only internationalized pathnames matcher: ['/', '/(fr|en)/:path*','/((?!api|_next|favicon.ico|favicon.svg).*)'], };