-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmiddleware.js
More file actions
35 lines (27 loc) · 890 Bytes
/
middleware.js
File metadata and controls
35 lines (27 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { NextResponse } from "next/server";
import { match } from '@formatjs/intl-localematcher'
import Negotiator from "negotiator";
const locales = ['en', 'fr']
const defaultLocale = 'en'
function getLocale(request) {
const languages = new Negotiator({ headers: request.headers }).languages(locales)
return match(languages, locales, defaultLocale)
}
export function middleware(request) {
/*
const { pathname } = request.nextUrl
const pathnameHasLocale = locales.some(
(locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`
)
if (pathnameHasLocale) return
const locale = getLocale(request)
request.nextUrl.pathname = `/${locale}${pathname}`
return NextResponse.redirect(request.nextUrl)
*/
}
export const config = {
matcher: [
// Skip all internal paths (_next) and public assets
'/((?!_next|images|favicon.ico).*)',
],
}