mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 16:03:21 +00:00
refactor: Creation d'un provider et d'un systeme de middleware
This commit is contained in:
@ -1,24 +1,5 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import createMiddleware from 'next-intl/middleware';
|
||||
import { routing } from '@/i18n/routing';
|
||||
const middleware = createMiddleware(routing);
|
||||
import { stackMiddlewares } from "@/middlewares/stackHandler";
|
||||
import { withLocale } from "@/middlewares/withLocale";
|
||||
|
||||
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).*)'],
|
||||
};
|
||||
const middlewares = [withLocale];
|
||||
export default stackMiddlewares(middlewares);
|
||||
Reference in New Issue
Block a user