Skip to content

Commit b43cdf2

Browse files
committed
feat: Allow optimal routing
Introduced a new field to allow bypassing middleware when possible
1 parent 663c539 commit b43cdf2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/next-intl/src/middleware/middleware.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ export default function createMiddleware<
266266
} else {
267267
const internalHref = formatPathname(
268268
unprefixedInternalPathname,
269-
getLocaleAsPrefix(locale),
269+
resolvedRouting.optimalRouting
270+
? undefined
271+
: getLocaleAsPrefix(locale),
270272
request.nextUrl.search
271273
);
272274

packages/next-intl/src/routing/config.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ export type RoutingConfig<
6666
**/
6767
alternateLinks?: boolean;
6868

69+
/**
70+
* Allows having the optimal routing for the current request by bypassing middleware
71+
* and using the default locale when no locale is presented via the URL or domains.
72+
**/
73+
optimalRouting?: boolean;
74+
6975
/**
7076
* By setting this to `false`, the cookie as well as the `accept-language` header will no longer be used for locale detection.
7177
* @see https://next-intl.dev/docs/routing/middleware#locale-detection

0 commit comments

Comments
 (0)