Middleware
The NextGlobeGen middleware can be enabled in middleware.ts
file. The middleware handles locale negotiation and adds alternate links of the page to the response headers.
src/middleware.ts
export { middleware } from "next-globe-gen/middleware";
export const config = {
// Matcher ignoring next internals and static assets
matcher: ["/((?!_next|.*\\.).*)"],
};
Parametersโ
middleware(request: NextRequest, opts?: { skipAlternateLinkHeader?: boolean });
Param | Type | Required | Description |
---|---|---|---|
request | NextRequest | Yes | The request that is passed to Next.js middleware function |
opts.skipAlternateLinkHeader | boolean | - | If the alternate link header should be skipped or not (default: false) |
Returnsโ
middleware
returns a NextResponse
instance, which can be further modified.
With other middleware logicโ
If you need to use custom middleware logic, call the middleware yourself with the given request instance and modify the returned response.
src/middleware.ts
import nextGlobeGenMiddleware from "next-globe-gen/middleware";
export function middleware(request: NextRequest) {
const response = nextGlobeGenMiddleware(request);
/**
* Other custom logic that possibly modify the response
*/
return response;
}
export const config = {
// Matcher ignoring next internals and static assets
matcher: ["/((?!_next|.*\\.).*)"],
};