Skip to content

Commit 7e23ca1

Browse files
committed
refactor: put optional prefix check in fn
1 parent bc9fba1 commit 7e23ca1

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

packages/nextjs/src/config/manifest/createRouteManifest.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,20 @@ function buildRegexForDynamicRoute(routePath: string): {
9999
pattern = `^/${regexSegments.join('/')}$`;
100100
}
101101

102-
// Detect if the first parameter is a common i18n prefix segment
103-
// Common patterns: locale, lang, language
102+
return { regex: pattern, paramNames, hasOptionalPrefix: hasOptionalPrefix(paramNames) };
103+
}
104+
105+
/**
106+
* Detect if the first parameter is a common i18n prefix segment
107+
* Common patterns: locale, lang, language
108+
*/
109+
function hasOptionalPrefix(paramNames: string[]): boolean {
104110
const firstParam = paramNames[0];
105-
const hasOptionalPrefix =
106-
firstParam !== undefined && (firstParam === 'locale' || firstParam === 'lang' || firstParam === 'language');
111+
if (firstParam === undefined) {
112+
return false;
113+
}
107114

108-
return { regex: pattern, paramNames, hasOptionalPrefix };
115+
return firstParam === 'locale' || firstParam === 'lang' || firstParam === 'language';
109116
}
110117

111118
function scanAppDirectory(

0 commit comments

Comments
 (0)