Skip to content

Commit

Permalink
Allow optimal routing
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Feb 24, 2025
1 parent 663c539 commit f53d80b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/next-intl/src/middleware/middleware.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ export default function createMiddleware<
} else {
const internalHref = formatPathname(
unprefixedInternalPathname,
getLocaleAsPrefix(locale),
resolvedRouting.optimalRouting
? undefined
: getLocaleAsPrefix(locale),
request.nextUrl.search
);

Expand Down
6 changes: 6 additions & 0 deletions packages/next-intl/src/routing/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export type RoutingConfig<
**/
alternateLinks?: boolean;

/**
* Allows having the optimal routing for the current request by bypassing middleware
* and using the default locale when no locale is presented via the URL or domains.
**/
optimalRouting?: boolean;

/**
* By setting this to `false`, the cookie as well as the `accept-language` header will no longer be used for locale detection.
* @see https://next-intl.dev/docs/routing/middleware#locale-detection
Expand Down

0 comments on commit f53d80b

Please sign in to comment.