@i18n-micro/path-strategy 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/dist/base-strategy-BNdOdpRE.cjs +2 -0
- package/dist/base-strategy-BNdOdpRE.cjs.map +1 -0
- package/dist/{base-strategy-PVpkf05w.js → base-strategy-DmOQzfP1.js} +127 -109
- package/dist/base-strategy-DmOQzfP1.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.mjs +8 -8
- package/dist/index.mjs.map +1 -1
- package/dist/no-prefix-strategy.cjs +1 -1
- package/dist/no-prefix-strategy.cjs.map +1 -1
- package/dist/no-prefix-strategy.d.ts +1 -2
- package/dist/no-prefix-strategy.mjs +2 -2
- package/dist/no-prefix-strategy.mjs.map +1 -1
- package/dist/prefix-and-default-strategy.cjs +1 -1
- package/dist/prefix-and-default-strategy.cjs.map +1 -1
- package/dist/prefix-and-default-strategy.d.ts +1 -2
- package/dist/prefix-and-default-strategy.mjs +2 -7
- package/dist/prefix-and-default-strategy.mjs.map +1 -1
- package/dist/prefix-except-default-strategy.cjs +1 -1
- package/dist/prefix-except-default-strategy.cjs.map +1 -1
- package/dist/prefix-except-default-strategy.d.ts +2 -4
- package/dist/prefix-except-default-strategy.mjs +58 -57
- package/dist/prefix-except-default-strategy.mjs.map +1 -1
- package/dist/prefix-strategy.cjs +1 -1
- package/dist/prefix-strategy.cjs.map +1 -1
- package/dist/prefix-strategy.d.ts +1 -2
- package/dist/prefix-strategy.mjs +1 -1
- package/dist/prefix-strategy.mjs.map +1 -1
- package/dist/types.d.ts +0 -1
- package/package.json +2 -2
- package/dist/base-strategy-CF5n6eGB.cjs +0 -2
- package/dist/base-strategy-CF5n6eGB.cjs.map +0 -1
- package/dist/base-strategy-PVpkf05w.js.map +0 -1
|
@@ -260,7 +260,6 @@ declare interface PathStrategyContext {
|
|
|
260
260
|
globalLocaleRoutes?: GlobalLocaleRoutes;
|
|
261
261
|
routeLocales?: Record<string, string[]>;
|
|
262
262
|
routesLocaleLinks?: Record<string, string>;
|
|
263
|
-
includeDefaultLocaleRoute?: boolean;
|
|
264
263
|
noPrefixRedirect?: boolean;
|
|
265
264
|
debug?: boolean;
|
|
266
265
|
router: RouterAdapter;
|
|
@@ -327,7 +326,7 @@ declare class RouteResolver {
|
|
|
327
326
|
constructor(ctx: PathStrategyContext);
|
|
328
327
|
/**
|
|
329
328
|
* Substitutes params into path template (:key, :key(), [...key]).
|
|
330
|
-
* Uses
|
|
329
|
+
* Uses a single pre-compiled regex for all keys in one pass — no per-key RegExp allocation.
|
|
331
330
|
*/
|
|
332
331
|
resolvePathWithParams(path: string, params?: Record<string, unknown>): string;
|
|
333
332
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as F, j as i, n as U, h as u, k as R, d as v, t as S, w as q, a as w, g as C, i as k } from "./base-strategy-
|
|
1
|
+
import { B as F, j as i, n as U, h as u, k as R, d as v, t as S, w as q, a as w, g as C, i as k } from "./base-strategy-DmOQzfP1.js";
|
|
2
2
|
class _ extends F {
|
|
3
3
|
buildLocalizedPath(t, e, a) {
|
|
4
4
|
return i(e, U(t));
|
|
@@ -39,12 +39,7 @@ class _ extends F {
|
|
|
39
39
|
}
|
|
40
40
|
const c = h.params && Object.keys(h.params ?? {}).length > 0;
|
|
41
41
|
if (l && c) {
|
|
42
|
-
const s = this.tryResolveByLocalizedNameWithParams(
|
|
43
|
-
l,
|
|
44
|
-
t,
|
|
45
|
-
h.params ?? {},
|
|
46
|
-
h
|
|
47
|
-
);
|
|
42
|
+
const s = this.tryResolveByLocalizedNameWithParams(l, t, h.params ?? {}, h);
|
|
48
43
|
if (s !== null) {
|
|
49
44
|
const r = s.path ?? "", { pathWithoutLocale: m } = this.getPathWithoutLocale(r), P = m === "/" || m === "" ? `/${t}` : i(`/${t}`, u(m)), W = R(P, s.query, s.hash), B = {
|
|
50
45
|
...s,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefix-and-default-strategy.mjs","sources":["../src/strategies/prefix-and-default.ts"],"sourcesContent":["import type { NormalizedRouteInput, ResolvedRouteLike, RouteLike, SwitchLocaleOptions } from '../core/types'\nimport { BasePathStrategy } from './base-strategy'\nimport { isSamePath, withLeadingSlash, withoutLeadingSlash } from 'ufo'\nimport { buildUrl, getCleanPath, joinUrl, normalizePath, normalizePathForCompare, transformNameKeyToPath } from '../utils/path'\nimport { isIndexRouteName } from '../utils/route-name'\n\n/**\n * prefix_and_default: default locale has both /path and /en/path.\n * We use prefixed route names for consistency (localized-name-en).\n */\nexport class PrefixAndDefaultPathStrategy extends BasePathStrategy {\n protected buildLocalizedPath(path: string, locale: string, _isCustom: boolean): string {\n return joinUrl(locale, normalizePath(path))\n }\n\n protected buildLocalizedRouteName(baseName: string, locale: string): string {\n return this.buildLocalizedName(baseName, locale)\n }\n\n override switchLocaleRoute(\n fromLocale: string,\n toLocale: string,\n route: ResolvedRouteLike,\n options: SwitchLocaleOptions,\n ): RouteLike | string {\n const baseName = this.getBaseRouteName(route, fromLocale)\n if (!baseName) return route\n\n // Try route name with locale suffix first (custom paths), then without suffix (standard routes)\n const nameWithSuffix = this.buildLocalizedName(baseName, toLocale)\n const nameWithoutSuffix = `${this.getLocalizedRouteNamePrefix()}${baseName}`\n let targetName: string\n let needsLocaleParam = false\n\n if (this.ctx.router.hasRoute(nameWithSuffix)) {\n targetName = nameWithSuffix\n }\n else if (this.ctx.router.hasRoute(nameWithoutSuffix)) {\n targetName = nameWithoutSuffix\n needsLocaleParam = true\n }\n else if (this.ctx.router.hasRoute(baseName)) {\n targetName = baseName\n }\n else {\n return { ...route, name: nameWithSuffix }\n }\n\n const i18nParams = options.i18nRouteParams?.[toLocale] || {}\n const newParams: Record<string, unknown> = { ...(route.params || {}), ...i18nParams }\n if (needsLocaleParam) {\n newParams.locale = toLocale\n }\n else {\n delete (newParams as Record<string, unknown>).locale\n }\n\n return this.applyBaseUrl(toLocale, {\n name: targetName,\n params: newParams,\n query: route.query,\n hash: route.hash,\n }) as RouteLike\n }\n\n protected override resolveLocaleRoute(\n targetLocale: string,\n normalized: NormalizedRouteInput,\n currentRoute?: ResolvedRouteLike,\n ): RouteLike | string {\n if (normalized.kind === 'path') {\n const resolvedPath = this.resolvePathForLocale(normalized.path, targetLocale)\n const prefix = `/${targetLocale}`\n return this.applyBaseUrl(targetLocale, joinUrl(prefix, withLeadingSlash(resolvedPath)))\n }\n\n const { inputName, sourceRoute, resolved } = normalized\n if (inputName) {\n const unlocalizedByName = this.getPathForUnlocalizedRouteByName(inputName)\n if (unlocalizedByName !== null) return unlocalizedByName\n }\n const hasParams = sourceRoute.params && Object.keys(sourceRoute.params ?? {}).length > 0\n if (inputName && hasParams) {\n const routeWithParams = this.tryResolveByLocalizedNameWithParams(\n inputName,\n targetLocale,\n sourceRoute.params ?? {},\n sourceRoute,\n )\n if (routeWithParams !== null) {\n const resolvedPath = routeWithParams.path ?? ''\n const { pathWithoutLocale } = this.getPathWithoutLocale(resolvedPath)\n const pathWithLocale = pathWithoutLocale === '/' || pathWithoutLocale === ''\n ? `/${targetLocale}`\n : joinUrl(`/${targetLocale}`, withLeadingSlash(pathWithoutLocale))\n const fullPathWithLocale = buildUrl(pathWithLocale, routeWithParams.query, routeWithParams.hash)\n const routeWithPath: RouteLike = {\n ...routeWithParams,\n path: pathWithLocale,\n fullPath: fullPathWithLocale,\n }\n return this.applyBaseUrl(targetLocale, routeWithPath)\n }\n }\n\n const unlocalizedPath = this.getPathForUnlocalizedRoute(resolved)\n if (unlocalizedPath !== null) return this.applyBaseUrl(targetLocale, unlocalizedPath)\n\n const customSegment = this.getCustomPathSegment(resolved, targetLocale)\n if (customSegment !== null) {\n const prefix = `/${targetLocale}`\n return this.applyBaseUrl(targetLocale, joinUrl(prefix, withLeadingSlash(customSegment)))\n }\n const baseName = this.getRouteBaseName(resolved) ?? inputName ?? resolved.name?.toString() ?? null\n if (inputName && !hasParams) {\n let routeByLocalizedName = this.tryResolveByLocalizedName(inputName, targetLocale, sourceRoute)\n const prefix = this.getLocalizedRouteNamePrefix()\n if (routeByLocalizedName === null && baseName != null && baseName !== inputName && inputName.startsWith(prefix)) {\n routeByLocalizedName = this.tryResolveByLocalizedName(baseName, targetLocale, sourceRoute)\n }\n if (routeByLocalizedName !== null) {\n // Router may return path without locale prefix (e.g. Nuxt file-based /contact). For prefix_and_default\n // we always need path with locale (e.g. /en/contact).\n const resolvedPath = routeByLocalizedName.path ?? ''\n const { pathWithoutLocale } = this.getPathWithoutLocale(resolvedPath)\n const pathWithLocale = pathWithoutLocale === '/' || pathWithoutLocale === ''\n ? `/${targetLocale}`\n : joinUrl(`/${targetLocale}`, withLeadingSlash(pathWithoutLocale))\n const fullPathWithLocale = buildUrl(pathWithLocale, routeByLocalizedName.query, routeByLocalizedName.hash)\n const routeWithPath: RouteLike = {\n ...routeByLocalizedName,\n path: pathWithLocale,\n fullPath: fullPathWithLocale,\n }\n return this.applyBaseUrl(targetLocale, routeWithPath)\n }\n }\n if (resolved.path && resolved.path !== '/' && resolved.name) {\n const { pathWithoutLocale } = this.getPathWithoutLocaleAndBaseName(resolved)\n if (pathWithoutLocale && pathWithoutLocale !== '/') {\n return this.applyBaseUrl(targetLocale, joinUrl(`/${targetLocale}`, withLeadingSlash(pathWithoutLocale)))\n }\n }\n\n const fromLocale = currentRoute\n ? this.detectLocaleFromName(currentRoute.name)\n : this.detectLocaleFromName(resolved.name)\n\n const fallbackBaseName = fromLocale\n ? this.getBaseRouteName(resolved, fromLocale)\n : baseName\n\n if (!fallbackBaseName) {\n // Never return unprefixed path for prefix_and_default. Build path from resolved.\n const { pathWithoutLocale } = this.getPathWithoutLocale(resolved.path ?? '/')\n const pathWithLocale = pathWithoutLocale === '/' || pathWithoutLocale === ''\n ? `/${targetLocale}`\n : joinUrl(`/${targetLocale}`, withLeadingSlash(pathWithoutLocale))\n const fullPathWithLocale = buildUrl(pathWithLocale, sourceRoute.query, sourceRoute.hash)\n return this.applyBaseUrl(targetLocale, {\n ...sourceRoute,\n path: pathWithLocale,\n fullPath: fullPathWithLocale,\n })\n }\n\n const targetName = this.buildLocalizedName(fallbackBaseName, targetLocale)\n\n const pathWithoutLocale = isIndexRouteName(fallbackBaseName)\n ? '/'\n : joinUrl('/', transformNameKeyToPath(fallbackBaseName))\n const pathForLocale = joinUrl(`/${targetLocale}`, withLeadingSlash(pathWithoutLocale))\n const withBase = this.applyBaseUrl(targetLocale, pathForLocale)\n const pathStr = typeof withBase === 'string' ? withBase : (withBase as RouteLike).path ?? pathForLocale\n\n const newRoute: RouteLike = {\n name: targetName,\n path: pathStr,\n fullPath: pathStr,\n params: { ...resolved.params, ...sourceRoute.params },\n query: { ...resolved.query, ...sourceRoute.query },\n hash: sourceRoute.hash ?? resolved.hash,\n }\n return this.applyBaseUrl(targetLocale, newRoute)\n }\n\n override getCanonicalPath(route: ResolvedRouteLike, targetLocale: string): string | null {\n const segment = this.getCustomPathSegment(route, targetLocale)\n if (!segment) return null\n return joinUrl(`/${targetLocale}`, withLeadingSlash(segment))\n }\n\n protected detectLocaleFromName(name: string | null): string | null {\n if (!name) return null\n for (const locale of this.ctx.locales) {\n if (name.endsWith(`-${locale.code}`)) {\n return locale.code\n }\n }\n return null\n }\n\n resolveLocaleFromPath(path: string): string | null {\n const { localeFromPath } = this.getPathWithoutLocale(path)\n return localeFromPath\n }\n\n getRedirect(currentPath: string, detectedLocale: string): string | null {\n const { pathWithoutLocale, localeFromPath } = this.getPathWithoutLocale(currentPath)\n // Unlocalized routes (globalLocaleRoutes[key] === false): redirect /locale/path to /path\n const gr = this.ctx.globalLocaleRoutes\n if (gr && localeFromPath !== null) {\n const pathKey = pathWithoutLocale === '/' ? '/' : withoutLeadingSlash(pathWithoutLocale)\n if (gr[pathWithoutLocale] === false || gr[pathKey] === false) {\n return normalizePathForCompare(pathWithoutLocale === '/' ? '/' : pathWithoutLocale)\n }\n }\n const expectedPath = this.buildPathWithPrefix(pathWithoutLocale, detectedLocale)\n const currentPathOnly = getCleanPath(currentPath)\n if (localeFromPath === detectedLocale && isSamePath(currentPathOnly, expectedPath)) {\n return null\n }\n return expectedPath\n }\n\n private buildPathWithPrefix(pathWithoutLocale: string, locale: string): string {\n const resolved = this.resolvePathForLocale(pathWithoutLocale, locale)\n if (resolved === '/' || resolved === '') {\n return `/${locale}`\n }\n return joinUrl(`/${locale}`, resolved)\n }\n\n /**\n * Formats path for router.resolve.\n * prefix_and_default: always add locale prefix.\n */\n formatPathForResolve(path: string, fromLocale: string, _toLocale: string): string {\n return `/${fromLocale}${path}`\n }\n\n /**\n * prefix_and_default: both / and /locale are valid for any locale.\n * Does NOT redirect if user explicitly navigates to a locale path.\n * Only redirects from paths without locale prefix.\n */\n getClientRedirect(currentPath: string, _preferredLocale: string): string | null {\n const { pathWithoutLocale, localeFromPath } = this.getPathWithoutLocale(currentPath)\n\n // Check if route is unlocalized\n const gr = this.ctx.globalLocaleRoutes\n const pathKey = pathWithoutLocale === '/' ? '/' : pathWithoutLocale.replace(/^\\//, '')\n if (gr && (gr[pathWithoutLocale] === false || gr[pathKey] === false)) {\n return null // Unlocalized routes - no redirect\n }\n\n // URL has locale prefix - user explicitly navigated here, don't redirect\n if (localeFromPath !== null) return null\n\n // Root path without locale is valid for any locale - no redirect\n if (currentPath === '/' || currentPath === '') return null\n\n // Non-root path without locale - this shouldn't happen normally in prefix_and_default\n // but if it does, we could redirect. For now, let Vue Router handle it.\n return null\n }\n}\n\n/** Alias for Nuxt alias consumption. */\nexport { PrefixAndDefaultPathStrategy as Strategy }\n"],"names":["PrefixAndDefaultPathStrategy","BasePathStrategy","path","locale","_isCustom","joinUrl","normalizePath","baseName","fromLocale","toLocale","route","options","nameWithSuffix","nameWithoutSuffix","targetName","needsLocaleParam","i18nParams","newParams","targetLocale","normalized","currentRoute","resolvedPath","prefix","withLeadingSlash","inputName","sourceRoute","resolved","unlocalizedByName","hasParams","routeWithParams","pathWithoutLocale","pathWithLocale","fullPathWithLocale","buildUrl","routeWithPath","unlocalizedPath","customSegment","routeByLocalizedName","fallbackBaseName","isIndexRouteName","transformNameKeyToPath","pathForLocale","withBase","pathStr","newRoute","segment","name","localeFromPath","currentPath","detectedLocale","gr","pathKey","withoutLeadingSlash","normalizePathForCompare","expectedPath","currentPathOnly","getCleanPath","isSamePath","_toLocale","_preferredLocale"],"mappings":";AAUO,MAAMA,UAAqCC,EAAiB;AAAA,EACvD,mBAAmBC,GAAcC,GAAgBC,GAA4B;AACrF,WAAOC,EAAQF,GAAQG,EAAcJ,CAAI,CAAC;AAAA,EAC5C;AAAA,EAEU,wBAAwBK,GAAkBJ,GAAwB;AAC1E,WAAO,KAAK,mBAAmBI,GAAUJ,CAAM;AAAA,EACjD;AAAA,EAES,kBACPK,GACAC,GACAC,GACAC,GACoB;AACpB,UAAMJ,IAAW,KAAK,iBAAiBG,GAAOF,CAAU;AACxD,QAAI,CAACD,EAAU,QAAOG;AAGtB,UAAME,IAAiB,KAAK,mBAAmBL,GAAUE,CAAQ,GAC3DI,IAAoB,GAAG,KAAK,4BAAA,CAA6B,GAAGN,CAAQ;AAC1E,QAAIO,GACAC,IAAmB;AAEvB,QAAI,KAAK,IAAI,OAAO,SAASH,CAAc;AACzC,MAAAE,IAAaF;AAAA,aAEN,KAAK,IAAI,OAAO,SAASC,CAAiB;AACjD,MAAAC,IAAaD,GACbE,IAAmB;AAAA,aAEZ,KAAK,IAAI,OAAO,SAASR,CAAQ;AACxC,MAAAO,IAAaP;AAAA;AAGb,aAAO,EAAE,GAAGG,GAAO,MAAME,EAAA;AAG3B,UAAMI,IAAaL,EAAQ,kBAAkBF,CAAQ,KAAK,CAAA,GACpDQ,IAAqC,EAAE,GAAIP,EAAM,UAAU,CAAA,GAAK,GAAGM,EAAA;AACzE,WAAID,IACFE,EAAU,SAASR,IAGnB,OAAQQ,EAAsC,QAGzC,KAAK,aAAaR,GAAU;AAAA,MACjC,MAAMK;AAA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,IAAIlD,CAAU,GAAGN,CAAI;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,kBAAkB8C,GAAqBW,GAAyC;AAC9E,UAAM,EAAE,mBAAA7B,GAAmB,gBAAAiB,EAAA,IAAmB,KAAK,qBAAqBC,CAAW,GAG7EE,IAAK,KAAK,IAAI,oBACdC,IAAUrB,MAAsB,MAAM,MAAMA,EAAkB,QAAQ,OAAO,EAAE;AASrF,WARIoB,MAAOA,EAAGpB,CAAiB,MAAM,MAASoB,EAAGC,CAAO,MAAM,OAK1DJ,MAAmB,QAGnBC,MAAgB,OAAOA,MAAgB,IAAW;AAAA,EAKxD;AACF;"}
|
|
1
|
+
{"version":3,"file":"prefix-and-default-strategy.mjs","sources":["../src/strategies/prefix-and-default.ts"],"sourcesContent":["import { isSamePath, withLeadingSlash, withoutLeadingSlash } from 'ufo'\nimport type { NormalizedRouteInput, ResolvedRouteLike, RouteLike, SwitchLocaleOptions } from '../core/types'\nimport { buildUrl, getCleanPath, joinUrl, normalizePath, normalizePathForCompare, transformNameKeyToPath } from '../utils/path'\nimport { isIndexRouteName } from '../utils/route-name'\nimport { BasePathStrategy } from './base-strategy'\n\n/**\n * prefix_and_default: default locale has both /path and /en/path.\n * We use prefixed route names for consistency (localized-name-en).\n */\nexport class PrefixAndDefaultPathStrategy extends BasePathStrategy {\n protected buildLocalizedPath(path: string, locale: string, _isCustom: boolean): string {\n return joinUrl(locale, normalizePath(path))\n }\n\n protected buildLocalizedRouteName(baseName: string, locale: string): string {\n return this.buildLocalizedName(baseName, locale)\n }\n\n override switchLocaleRoute(fromLocale: string, toLocale: string, route: ResolvedRouteLike, options: SwitchLocaleOptions): RouteLike | string {\n const baseName = this.getBaseRouteName(route, fromLocale)\n if (!baseName) return route\n\n // Try route name with locale suffix first (custom paths), then without suffix (standard routes)\n const nameWithSuffix = this.buildLocalizedName(baseName, toLocale)\n const nameWithoutSuffix = `${this.getLocalizedRouteNamePrefix()}${baseName}`\n let targetName: string\n let needsLocaleParam = false\n\n if (this.ctx.router.hasRoute(nameWithSuffix)) {\n targetName = nameWithSuffix\n } else if (this.ctx.router.hasRoute(nameWithoutSuffix)) {\n targetName = nameWithoutSuffix\n needsLocaleParam = true\n } else if (this.ctx.router.hasRoute(baseName)) {\n targetName = baseName\n } else {\n return { ...route, name: nameWithSuffix }\n }\n\n const i18nParams = options.i18nRouteParams?.[toLocale] || {}\n const newParams: Record<string, unknown> = { ...(route.params || {}), ...i18nParams }\n if (needsLocaleParam) {\n newParams.locale = toLocale\n } else {\n delete (newParams as Record<string, unknown>).locale\n }\n\n return this.applyBaseUrl(toLocale, {\n name: targetName,\n params: newParams,\n query: route.query,\n hash: route.hash,\n }) as RouteLike\n }\n\n protected override resolveLocaleRoute(\n targetLocale: string,\n normalized: NormalizedRouteInput,\n currentRoute?: ResolvedRouteLike,\n ): RouteLike | string {\n if (normalized.kind === 'path') {\n const resolvedPath = this.resolvePathForLocale(normalized.path, targetLocale)\n const prefix = `/${targetLocale}`\n return this.applyBaseUrl(targetLocale, joinUrl(prefix, withLeadingSlash(resolvedPath)))\n }\n\n const { inputName, sourceRoute, resolved } = normalized\n if (inputName) {\n const unlocalizedByName = this.getPathForUnlocalizedRouteByName(inputName)\n if (unlocalizedByName !== null) return unlocalizedByName\n }\n const hasParams = sourceRoute.params && Object.keys(sourceRoute.params ?? {}).length > 0\n if (inputName && hasParams) {\n const routeWithParams = this.tryResolveByLocalizedNameWithParams(inputName, targetLocale, sourceRoute.params ?? {}, sourceRoute)\n if (routeWithParams !== null) {\n const resolvedPath = routeWithParams.path ?? ''\n const { pathWithoutLocale } = this.getPathWithoutLocale(resolvedPath)\n const pathWithLocale =\n pathWithoutLocale === '/' || pathWithoutLocale === ''\n ? `/${targetLocale}`\n : joinUrl(`/${targetLocale}`, withLeadingSlash(pathWithoutLocale))\n const fullPathWithLocale = buildUrl(pathWithLocale, routeWithParams.query, routeWithParams.hash)\n const routeWithPath: RouteLike = {\n ...routeWithParams,\n path: pathWithLocale,\n fullPath: fullPathWithLocale,\n }\n return this.applyBaseUrl(targetLocale, routeWithPath)\n }\n }\n\n const unlocalizedPath = this.getPathForUnlocalizedRoute(resolved)\n if (unlocalizedPath !== null) return this.applyBaseUrl(targetLocale, unlocalizedPath)\n\n const customSegment = this.getCustomPathSegment(resolved, targetLocale)\n if (customSegment !== null) {\n const prefix = `/${targetLocale}`\n return this.applyBaseUrl(targetLocale, joinUrl(prefix, withLeadingSlash(customSegment)))\n }\n const baseName = this.getRouteBaseName(resolved) ?? inputName ?? resolved.name?.toString() ?? null\n if (inputName && !hasParams) {\n let routeByLocalizedName = this.tryResolveByLocalizedName(inputName, targetLocale, sourceRoute)\n const prefix = this.getLocalizedRouteNamePrefix()\n if (routeByLocalizedName === null && baseName != null && baseName !== inputName && inputName.startsWith(prefix)) {\n routeByLocalizedName = this.tryResolveByLocalizedName(baseName, targetLocale, sourceRoute)\n }\n if (routeByLocalizedName !== null) {\n // Router may return path without locale prefix (e.g. Nuxt file-based /contact). For prefix_and_default\n // we always need path with locale (e.g. /en/contact).\n const resolvedPath = routeByLocalizedName.path ?? ''\n const { pathWithoutLocale } = this.getPathWithoutLocale(resolvedPath)\n const pathWithLocale =\n pathWithoutLocale === '/' || pathWithoutLocale === ''\n ? `/${targetLocale}`\n : joinUrl(`/${targetLocale}`, withLeadingSlash(pathWithoutLocale))\n const fullPathWithLocale = buildUrl(pathWithLocale, routeByLocalizedName.query, routeByLocalizedName.hash)\n const routeWithPath: RouteLike = {\n ...routeByLocalizedName,\n path: pathWithLocale,\n fullPath: fullPathWithLocale,\n }\n return this.applyBaseUrl(targetLocale, routeWithPath)\n }\n }\n if (resolved.path && resolved.path !== '/' && resolved.name) {\n const { pathWithoutLocale } = this.getPathWithoutLocaleAndBaseName(resolved)\n if (pathWithoutLocale && pathWithoutLocale !== '/') {\n return this.applyBaseUrl(targetLocale, joinUrl(`/${targetLocale}`, withLeadingSlash(pathWithoutLocale)))\n }\n }\n\n const fromLocale = currentRoute ? this.detectLocaleFromName(currentRoute.name) : this.detectLocaleFromName(resolved.name)\n\n const fallbackBaseName = fromLocale ? this.getBaseRouteName(resolved, fromLocale) : baseName\n\n if (!fallbackBaseName) {\n // Never return unprefixed path for prefix_and_default. Build path from resolved.\n const { pathWithoutLocale } = this.getPathWithoutLocale(resolved.path ?? '/')\n const pathWithLocale =\n pathWithoutLocale === '/' || pathWithoutLocale === '' ? `/${targetLocale}` : joinUrl(`/${targetLocale}`, withLeadingSlash(pathWithoutLocale))\n const fullPathWithLocale = buildUrl(pathWithLocale, sourceRoute.query, sourceRoute.hash)\n return this.applyBaseUrl(targetLocale, {\n ...sourceRoute,\n path: pathWithLocale,\n fullPath: fullPathWithLocale,\n })\n }\n\n const targetName = this.buildLocalizedName(fallbackBaseName, targetLocale)\n\n const pathWithoutLocale = isIndexRouteName(fallbackBaseName) ? '/' : joinUrl('/', transformNameKeyToPath(fallbackBaseName))\n const pathForLocale = joinUrl(`/${targetLocale}`, withLeadingSlash(pathWithoutLocale))\n const withBase = this.applyBaseUrl(targetLocale, pathForLocale)\n const pathStr = typeof withBase === 'string' ? withBase : ((withBase as RouteLike).path ?? pathForLocale)\n\n const newRoute: RouteLike = {\n name: targetName,\n path: pathStr,\n fullPath: pathStr,\n params: { ...resolved.params, ...sourceRoute.params },\n query: { ...resolved.query, ...sourceRoute.query },\n hash: sourceRoute.hash ?? resolved.hash,\n }\n return this.applyBaseUrl(targetLocale, newRoute)\n }\n\n override getCanonicalPath(route: ResolvedRouteLike, targetLocale: string): string | null {\n const segment = this.getCustomPathSegment(route, targetLocale)\n if (!segment) return null\n return joinUrl(`/${targetLocale}`, withLeadingSlash(segment))\n }\n\n protected detectLocaleFromName(name: string | null): string | null {\n if (!name) return null\n for (const locale of this.ctx.locales) {\n if (name.endsWith(`-${locale.code}`)) {\n return locale.code\n }\n }\n return null\n }\n\n resolveLocaleFromPath(path: string): string | null {\n const { localeFromPath } = this.getPathWithoutLocale(path)\n return localeFromPath\n }\n\n getRedirect(currentPath: string, detectedLocale: string): string | null {\n const { pathWithoutLocale, localeFromPath } = this.getPathWithoutLocale(currentPath)\n // Unlocalized routes (globalLocaleRoutes[key] === false): redirect /locale/path to /path\n const gr = this.ctx.globalLocaleRoutes\n if (gr && localeFromPath !== null) {\n const pathKey = pathWithoutLocale === '/' ? '/' : withoutLeadingSlash(pathWithoutLocale)\n if (gr[pathWithoutLocale] === false || gr[pathKey] === false) {\n return normalizePathForCompare(pathWithoutLocale === '/' ? '/' : pathWithoutLocale)\n }\n }\n const expectedPath = this.buildPathWithPrefix(pathWithoutLocale, detectedLocale)\n const currentPathOnly = getCleanPath(currentPath)\n if (localeFromPath === detectedLocale && isSamePath(currentPathOnly, expectedPath)) {\n return null\n }\n return expectedPath\n }\n\n private buildPathWithPrefix(pathWithoutLocale: string, locale: string): string {\n const resolved = this.resolvePathForLocale(pathWithoutLocale, locale)\n if (resolved === '/' || resolved === '') {\n return `/${locale}`\n }\n return joinUrl(`/${locale}`, resolved)\n }\n\n /**\n * Formats path for router.resolve.\n * prefix_and_default: always add locale prefix.\n */\n formatPathForResolve(path: string, fromLocale: string, _toLocale: string): string {\n return `/${fromLocale}${path}`\n }\n\n /**\n * prefix_and_default: both / and /locale are valid for any locale.\n * Does NOT redirect if user explicitly navigates to a locale path.\n * Only redirects from paths without locale prefix.\n */\n getClientRedirect(currentPath: string, _preferredLocale: string): string | null {\n const { pathWithoutLocale, localeFromPath } = this.getPathWithoutLocale(currentPath)\n\n // Check if route is unlocalized\n const gr = this.ctx.globalLocaleRoutes\n const pathKey = pathWithoutLocale === '/' ? '/' : pathWithoutLocale.replace(/^\\//, '')\n if (gr && (gr[pathWithoutLocale] === false || gr[pathKey] === false)) {\n return null // Unlocalized routes - no redirect\n }\n\n // URL has locale prefix - user explicitly navigated here, don't redirect\n if (localeFromPath !== null) return null\n\n // Root path without locale is valid for any locale - no redirect\n if (currentPath === '/' || currentPath === '') return null\n\n // Non-root path without locale - this shouldn't happen normally in prefix_and_default\n // but if it does, we could redirect. For now, let Vue Router handle it.\n return null\n }\n}\n\n/** Alias for Nuxt alias consumption. */\nexport { PrefixAndDefaultPathStrategy as Strategy }\n"],"names":["PrefixAndDefaultPathStrategy","BasePathStrategy","path","locale","_isCustom","joinUrl","normalizePath","baseName","fromLocale","toLocale","route","options","nameWithSuffix","nameWithoutSuffix","targetName","needsLocaleParam","i18nParams","newParams","targetLocale","normalized","currentRoute","resolvedPath","prefix","withLeadingSlash","inputName","sourceRoute","resolved","unlocalizedByName","hasParams","routeWithParams","pathWithoutLocale","pathWithLocale","fullPathWithLocale","buildUrl","routeWithPath","unlocalizedPath","customSegment","routeByLocalizedName","fallbackBaseName","isIndexRouteName","transformNameKeyToPath","pathForLocale","withBase","pathStr","newRoute","segment","name","localeFromPath","currentPath","detectedLocale","gr","pathKey","withoutLeadingSlash","normalizePathForCompare","expectedPath","currentPathOnly","getCleanPath","isSamePath","_toLocale","_preferredLocale"],"mappings":";AAUO,MAAMA,UAAqCC,EAAiB;AAAA,EACvD,mBAAmBC,GAAcC,GAAgBC,GAA4B;AACrF,WAAOC,EAAQF,GAAQG,EAAcJ,CAAI,CAAC;AAAA,EAC5C;AAAA,EAEU,wBAAwBK,GAAkBJ,GAAwB;AAC1E,WAAO,KAAK,mBAAmBI,GAAUJ,CAAM;AAAA,EACjD;AAAA,EAES,kBAAkBK,GAAoBC,GAAkBC,GAA0BC,GAAkD;AAC3I,UAAMJ,IAAW,KAAK,iBAAiBG,GAAOF,CAAU;AACxD,QAAI,CAACD,EAAU,QAAOG;AAGtB,UAAME,IAAiB,KAAK,mBAAmBL,GAAUE,CAAQ,GAC3DI,IAAoB,GAAG,KAAK,4BAAA,CAA6B,GAAGN,CAAQ;AAC1E,QAAIO,GACAC,IAAmB;AAEvB,QAAI,KAAK,IAAI,OAAO,SAASH,CAAc;AACzC,MAAAE,IAAaF;AAAA,aACJ,KAAK,IAAI,OAAO,SAASC,CAAiB;AACnD,MAAAC,IAAaD,GACbE,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Y,IACxE,OAEFA;AAAA,EACT;AAAA,EAEQ,oBAAoBxB,GAA2B3B,GAAwB;AAC7E,UAAMuB,IAAW,KAAK,qBAAqBI,GAAmB3B,CAAM;AACpE,WAAIuB,MAAa,OAAOA,MAAa,KAC5B,IAAIvB,CAAM,KAEZE,EAAQ,IAAIF,CAAM,IAAIuB,CAAQ;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,qBAAqBxB,GAAcM,GAAoBkD,GAA2B;AAChF,WAAO,IAAIlD,CAAU,GAAGN,CAAI;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,kBAAkB8C,GAAqBW,GAAyC;AAC9E,UAAM,EAAE,mBAAA7B,GAAmB,gBAAAiB,EAAA,IAAmB,KAAK,qBAAqBC,CAAW,GAG7EE,IAAK,KAAK,IAAI,oBACdC,IAAUrB,MAAsB,MAAM,MAAMA,EAAkB,QAAQ,OAAO,EAAE;AASrF,WARIoB,MAAOA,EAAGpB,CAAiB,MAAM,MAASoB,EAAGC,CAAO,MAAM,OAK1DJ,MAAmB,QAGnBC,MAAgB,OAAOA,MAAgB,IAAW;AAAA,EAKxD;AACF;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./base-strategy-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./base-strategy-BNdOdpRE.cjs");class B extends h.BasePathStrategy{shouldHavePrefix(t){if(t===this.ctx.defaultLocale)return!1;const a=this.ctx.locales.find(e=>e.code===t);return!(a?.baseUrl&&a?.baseDefault)}buildLocalizedPath(t,a,e){return this.shouldHavePrefix(a)?h.joinUrl(a,h.normalizePath(t)):h.normalizePath(t)}buildLocalizedRouteName(t,a){return this.shouldHavePrefix(a)?this.buildLocalizedName(t,a):t}switchLocaleRoute(t,a,e,r){const s=this.getBaseRouteName(e,t);if(!s)return e;let i;if(this.shouldHavePrefix(a)){const n=this.buildLocalizedName(s,a),f=`${this.getLocalizedRouteNamePrefix()}${s}`;i=this.ctx.router.hasRoute(n)?n:f}else i=s;if(this.ctx.router.hasRoute(i)){const n=r.i18nRouteParams?.[a]||{},f={...e.params||{},...n};this.shouldHavePrefix(a)?f.locale=a:delete f.locale;const g=this.ctx.router.resolve({name:i,params:f}),W={name:i,params:f,path:g?.path,fullPath:g?.fullPath,query:e.query,hash:e.hash};return this.applyBaseUrl(a,W)}const u=e.path?.replace(new RegExp(`^/${t}`),"")||"/",P=this.buildLocalizedPath(u,a,!1);return this.applyBaseUrl(a,{path:P,query:e.query,hash:e.hash})}resolveLocaleRoute(t,a,e){if(a.kind==="path"){const o=this.resolvePathForLocale(a.path,t);if(!this.shouldHavePrefix(t))return this.applyBaseUrl(t,o);const c=h.joinUrl(t,o);return this.applyBaseUrl(t,c)}const{inputName:r,sourceRoute:s,resolved:i}=a;if(r){const o=this.getPathForUnlocalizedRouteByName(r);if(o!==null)return this.preserveQueryAndHash(o,s);const m=`/${h.nameKeyLastSlash(r)}`,y={name:r,path:m,fullPath:m,params:s.params??{}},l=this.getCustomPathSegment(y,t);if(l!==null){const p=this.getNestedRouteInfo(r);let d;if(p){const v=this.getParentPathForTarget(p.parentKey,p.keyWithSlash,t,e),S=l.startsWith("/")?l.slice(1):l;d=v?h.joinUrl(v,S):h.normalizePath(l)}else d=h.normalizePath(l);if(!this.shouldHavePrefix(t))return this.preserveQueryAndHash(this.applyBaseUrl(t,d),s);const x=h.joinUrl(t,d);return this.preserveQueryAndHash(this.applyBaseUrl(t,x),s)}}const u=s.params&&Object.keys(s.params??{}).length>0;if(r&&u){if(!this.shouldHavePrefix(t)&&this.ctx.router.hasRoute(r)){const c=this.ctx.router.resolve({name:r,params:s.params,query:s.query,hash:s.hash});if(c?.path&&c.path!=="/"){const m={name:r,path:c.path,fullPath:c.fullPath,params:c.params,query:c.query??s.query,hash:c.hash??s.hash};return this.preserveQueryAndHash(this.applyBaseUrl(t,m),s)}}const o=this.tryResolveByLocalizedNameWithParams(r,t,s.params??{},s);if(o!==null){const c=this.applyBaseUrl(t,o);return this.preserveQueryAndHash(c,s)}}if(i.name!=null){const o=this.getPathForUnlocalizedRoute(i);if(o!==null)return this.preserveQueryAndHash(this.applyBaseUrl(t,o),s);const c=this.getCustomPathSegment(i,t);if(c!==null){const m=i.name?.toString()??r??"",y=m?this.getNestedRouteInfo(m):null;let l;if(y){const d=this.getParentPathForTarget(y.parentKey,y.keyWithSlash,t,e),x=c.startsWith("/")?c.slice(1):c;l=h.joinUrl(d,x)}else l=h.normalizePath(c);if(!this.shouldHavePrefix(t))return this.preserveQueryAndHash(this.applyBaseUrl(t,l),s);const p=h.joinUrl(t,l);return this.preserveQueryAndHash(this.applyBaseUrl(t,p),s)}if(i.path&&i.path!=="/"&&i.name){const{pathWithoutLocale:m,baseRouteName:y}=this.getPathWithoutLocaleAndBaseName(i),l=this.getCustomPathSegment(i,t),p=y?this.getNestedRouteInfo(y):null,d=!!p;let x;if(l!==null&&d&&p){const v=this.getParentPathForTarget(p.parentKey,p.keyWithSlash,t,e),S=l.startsWith("/")?l.slice(1):l;x=h.joinUrl(v,S)}else if(d&&l===null&&m&&m!=="/"&&p){const v=this.getParentPathForTarget(p.parentKey,p.keyWithSlash,t,e),S=h.lastPathSegment(m);x=v?h.joinUrl(v,S):m!=="/"?m:null}else x=l!==null&&!d?h.normalizePath(l):m&&m!=="/"?m:null;if(x){const v=this.detectLocaleFromName(i.name),S=v?this.getBaseRouteName(i,v):i.name?this.getRouteBaseName(i):null,U=S?this.shouldHavePrefix(t)?this.buildLocalizedName(S,t):S.toString():void 0,F=this.shouldHavePrefix(t)?h.joinUrl(t,x):x,b={...U?{name:U}:{},path:F,fullPath:F,params:{...i.params,...s.params},query:{...i.query,...s.query},hash:s.hash??i.hash};return this.preserveQueryAndHash(this.applyBaseUrl(t,b),s)}}}if(r){const c=`/${h.nameKeyLastSlash(r)}`,m={name:r,path:c,fullPath:c,params:s.params??{}},y=this.getCustomPathSegment(m,t);if(y!==null){const l=this.getNestedRouteInfo(r);let p;if(l){const x=this.getParentPathForTarget(l.parentKey,l.keyWithSlash,t,e),v=y.startsWith("/")?y.slice(1):y;p=h.joinUrl(x||"/",v)}else p=h.normalizePath(y);if(!this.shouldHavePrefix(t))return this.preserveQueryAndHash(this.applyBaseUrl(t,p),s);const d=h.joinUrl(t,p);return this.preserveQueryAndHash(this.applyBaseUrl(t,d),s)}}if(r&&!u){if(this.shouldHavePrefix(t)){const o=this.tryResolveByLocalizedName(r,t,s);if(o!==null)return this.preserveQueryAndHash(this.applyBaseUrl(t,o),s)}else if(this.ctx.router.hasRoute(r)){const o=this.ctx.router.resolve({name:r,params:s.params,query:s.query,hash:s.hash});if(o?.path)return this.preserveQueryAndHash(this.applyBaseUrl(t,{name:r,path:o.path,fullPath:o.fullPath,params:o.params,query:o.query??s.query,hash:o.hash??s.hash}),s)}}const P=e?this.detectLocaleFromName(e.name):this.detectLocaleFromName(i.name),n=P?this.getBaseRouteName(i,P):i.name??null;if(!n)return s;const f=this.shouldHavePrefix(t)?this.buildLocalizedName(n,t):n.toString(),g=h.isIndexRouteName(n)?"/":h.joinUrl("/",h.transformNameKeyToPath(n)),W=this.shouldHavePrefix(t)?h.joinUrl(t,g):g,R=this.applyBaseUrl(t,W),N=typeof R=="string"?R:R.path??W,H={name:f,path:N,fullPath:N,params:{...i.params,...s.params},query:{...i.query,...s.query},hash:s.hash??i.hash};return this.preserveQueryAndHash(this.applyBaseUrl(t,H),s)}getCanonicalPath(t,a){const e=this.getCustomPathSegment(t,a);if(!e)return null;const r=e.startsWith("/")?e:`/${e}`;return this.shouldHavePrefix(a)?h.cleanDoubleSlashes(`/${a}${r}`):h.cleanDoubleSlashes(r)}resolveLocaleFromPath(t){const{localeFromPath:a}=this.getPathWithoutLocale(t);return a||this.ctx.defaultLocale}getRedirect(t,a){const{pathWithoutLocale:e,localeFromPath:r}=this.getPathWithoutLocale(t),s=this.shouldHavePrefix(a),i=this.ctx.globalLocaleRoutes;if(i&&r!==null){const f=e==="/"?"/":h.withoutLeadingSlash(e);if(i[e]===!1||i[f]===!1)return h.normalizePathForCompare(e)}if(r!==null){if(r===this.ctx.defaultLocale)return h.normalizePathForCompare(e);if(r===a){const f=this.buildPathWithPrefix(e,a),g=h.getCleanPath(t);return h.isSamePath(g,f)?null:f}return this.buildPathWithPrefix(e,a)}if(s)return this.buildPathWithPrefix(e,a);const u=this.resolvePathForLocale(e,a),P=u.startsWith("/")?u:`/${u}`,n=h.getCleanPath(t);return h.isSamePath(n,P)?null:P}shouldReturn404(t){const{pathWithoutLocale:a,localeFromPath:e}=this.getPathWithoutLocale(t);return e===null?null:e===this.ctx.defaultLocale&&a==="/"?"Default locale should not have prefix":super.shouldReturn404(t)}isLocaleRules(t){const a=this.ctx.globalLocaleRoutes;if(!a||!t)return!1;const e=a[t];return typeof e=="object"&&e!==null&&!Array.isArray(e)}getNestedRouteInfo(t){if(!this.ctx.globalLocaleRoutes)return null;const e=h.nameKeyLastSlash(t),r=h.nameKeyFirstSlash(t);if(e.includes("/")&&this.isLocaleRules(e))return{parentKey:h.parentKeyFromSlashKey(e),keyWithSlash:e};if(r.includes("/")&&this.isLocaleRules(r))return{parentKey:h.parentKeyFromSlashKey(r),keyWithSlash:r};const s=h.parentKeyFromSlashKey(e);if(e.includes("/")&&s&&this.isLocaleRules(s))return{parentKey:s,keyWithSlash:e};const i=h.parentKeyFromSlashKey(r);return r.includes("/")&&i&&this.isLocaleRules(i)?{parentKey:i,keyWithSlash:r}:null}getParentPathForTarget(t,a,e,r){const s=this.ctx.globalLocaleRoutes,i=t&&s?.[t]&&typeof s[t]=="object"&&!Array.isArray(s[t])?s[t]:null;let u=i?.[e]?h.normalizePath(i[e]):"";if(!u&&r?.path){const P=h.getCleanPath(r.path),{pathWithoutLocale:n}=this.getPathWithoutLocale(P);u=h.normalizePath(n)}if(!u){const P=h.getPathSegments(a).slice(0,-1);u=P.length?h.joinUrl("/",...P):""}return u}buildPathWithPrefix(t,a){const e=this.resolvePathForLocale(t,a);return e==="/"||e===""?`/${a}`:h.joinUrl(`/${a}`,e)}detectLocaleFromName(t){if(!t)return null;for(const a of this.ctx.locales)if(t.endsWith(`-${a.code}`))return a.code;return null}formatPathForResolve(t,a,e){return e!==this.ctx.defaultLocale?`/${a}${t}`:t}getClientRedirect(t,a){const{pathWithoutLocale:e,localeFromPath:r}=this.getPathWithoutLocale(t),s=this.ctx.globalLocaleRoutes,i=e==="/"?"/":h.withoutLeadingSlash(e);if(s&&(s[e]===!1||s[i]===!1)||r!==null)return null;const u=this.resolvePathForLocale(e,a),P=this.shouldHavePrefix(a);let n;P?n=h.cleanDoubleSlashes(`/${a}${u.startsWith("/")?u:`/${u}`}`):n=u.startsWith("/")?u:`/${u}`,n!=="/"&&n.endsWith("/")&&(n=n.slice(0,-1));const f=h.getCleanPath(t);return h.isSamePath(f,n)?null:n}}exports.PrefixExceptDefaultPathStrategy=B;exports.Strategy=B;
|
|
2
2
|
//# sourceMappingURL=prefix-except-default-strategy.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefix-except-default-strategy.cjs","sources":["../src/strategies/prefix-except-default.ts"],"sourcesContent":["import type { NormalizedRouteInput, ResolvedRouteLike, RouteLike, SwitchLocaleOptions } from '../core/types'\nimport { BasePathStrategy } from './base-strategy'\nimport { cleanDoubleSlashes, isSamePath, withoutLeadingSlash } from 'ufo'\nimport { getCleanPath, getPathSegments, joinUrl, normalizePath, normalizePathForCompare, nameKeyFirstSlash, nameKeyLastSlash, parentKeyFromSlashKey, lastPathSegment, transformNameKeyToPath } from '../utils/path'\nimport { isIndexRouteName } from '../utils/route-name'\n\nexport class PrefixExceptDefaultPathStrategy extends BasePathStrategy {\n /**\n * For this strategy a prefix is required for all non-default locales,\n * unless includeDefaultLocaleRoute is explicitly enabled.\n */\n protected shouldHavePrefix(locale: string): boolean {\n if (this.ctx.includeDefaultLocaleRoute) return true\n if (locale === this.ctx.defaultLocale) return false\n // When locale has baseUrl with baseDefault=true, no prefix needed (uses root on separate domain)\n const localeObj = this.ctx.locales.find(l => l.code === locale)\n if (localeObj?.baseUrl && localeObj?.baseDefault) return false\n return true\n }\n\n protected buildLocalizedPath(path: string, locale: string, _isCustom: boolean): string {\n if (!this.shouldHavePrefix(locale)) return normalizePath(path)\n return joinUrl(locale, normalizePath(path))\n }\n\n protected buildLocalizedRouteName(baseName: string, locale: string): string {\n if (!this.shouldHavePrefix(locale)) return baseName\n return this.buildLocalizedName(baseName, locale)\n }\n\n override switchLocaleRoute(\n fromLocale: string,\n toLocale: string,\n route: ResolvedRouteLike,\n options: SwitchLocaleOptions,\n ): RouteLike | string {\n const baseName = this.getBaseRouteName(route, fromLocale)\n if (!baseName) return route\n\n // For non-default locale, try route name with locale suffix first (custom paths),\n // then without suffix (standard routes like \"localized-page\")\n let targetName: string\n if (this.shouldHavePrefix(toLocale)) {\n const nameWithSuffix = this.buildLocalizedName(baseName, toLocale)\n const nameWithoutSuffix = `${this.getLocalizedRouteNamePrefix()}${baseName}`\n targetName = this.ctx.router.hasRoute(nameWithSuffix) ? nameWithSuffix : nameWithoutSuffix\n }\n else {\n targetName = baseName\n }\n\n if (this.ctx.router.hasRoute(targetName)) {\n const i18nParams = options.i18nRouteParams?.[toLocale] || {}\n const newParams: Record<string, unknown> = { ...(route.params || {}), ...i18nParams }\n // Always set locale param for non-default locales because routes may have /:locale(...) in path\n if (this.shouldHavePrefix(toLocale)) {\n newParams.locale = toLocale\n }\n else {\n delete newParams.locale\n }\n\n // Resolve to get the actual path for applyBaseUrl\n const resolved = this.ctx.router.resolve({ name: targetName, params: newParams })\n const newRoute: RouteLike = {\n name: targetName,\n params: newParams,\n path: resolved?.path,\n fullPath: resolved?.fullPath,\n query: route.query,\n hash: route.hash,\n }\n\n return this.applyBaseUrl(toLocale, newRoute)\n }\n\n // Fallback: build path-based route\n const pathWithoutLocale = route.path?.replace(new RegExp(`^/${fromLocale}`), '') || '/'\n const targetPath = this.buildLocalizedPath(pathWithoutLocale, toLocale, false)\n return this.applyBaseUrl(toLocale, { path: targetPath, query: route.query, hash: route.hash })\n }\n\n protected override resolveLocaleRoute(\n targetLocale: string,\n normalized: NormalizedRouteInput,\n currentRoute?: ResolvedRouteLike,\n ): RouteLike | string {\n if (normalized.kind === 'path') {\n const path = this.resolvePathForLocale(normalized.path, targetLocale)\n if (!this.shouldHavePrefix(targetLocale)) return this.applyBaseUrl(targetLocale, path)\n const newPath = joinUrl(targetLocale, path)\n return this.applyBaseUrl(targetLocale, newPath)\n }\n\n const { inputName, sourceRoute, resolved } = normalized\n if (inputName) {\n const unlocalizedByName = this.getPathForUnlocalizedRouteByName(inputName)\n if (unlocalizedByName !== null) return this.preserveQueryAndHash(unlocalizedByName, sourceRoute)\n const keyLastSlash = nameKeyLastSlash(inputName)\n const syntheticPath = '/' + keyLastSlash\n const syntheticResolved: ResolvedRouteLike = {\n name: inputName,\n path: syntheticPath,\n fullPath: syntheticPath,\n params: sourceRoute.params ?? {},\n }\n const customBySynthetic = this.getCustomPathSegment(syntheticResolved, targetLocale)\n if (customBySynthetic !== null) {\n const nestedInfo = this.getNestedRouteInfo(inputName)\n let pathNorm: string\n if (nestedInfo) {\n const parentPath = this.getParentPathForTarget(nestedInfo.parentKey, nestedInfo.keyWithSlash, targetLocale, currentRoute)\n const segment = customBySynthetic.startsWith('/') ? customBySynthetic.slice(1) : customBySynthetic\n pathNorm = parentPath ? joinUrl(parentPath, segment) : normalizePath(customBySynthetic)\n }\n else {\n pathNorm = normalizePath(customBySynthetic)\n }\n if (!this.shouldHavePrefix(targetLocale)) {\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, pathNorm), sourceRoute)\n }\n const newPath = joinUrl(targetLocale, pathNorm)\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, newPath), sourceRoute)\n }\n }\n\n const hasParams = sourceRoute.params && Object.keys(sourceRoute.params ?? {}).length > 0\n if (inputName && hasParams) {\n // For default locale, try resolving base route name first (without localized prefix)\n if (!this.shouldHavePrefix(targetLocale) && this.ctx.router.hasRoute(inputName)) {\n const resolved = this.ctx.router.resolve({\n name: inputName,\n params: sourceRoute.params,\n query: sourceRoute.query,\n hash: sourceRoute.hash,\n })\n if (resolved?.path && resolved.path !== '/') {\n const routeResult: RouteLike = {\n name: inputName,\n path: resolved.path,\n fullPath: resolved.fullPath,\n params: resolved.params,\n query: resolved.query ?? sourceRoute.query,\n hash: resolved.hash ?? sourceRoute.hash,\n }\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, routeResult), sourceRoute)\n }\n }\n const routeWithParams = this.tryResolveByLocalizedNameWithParams(\n inputName,\n targetLocale,\n sourceRoute.params ?? {},\n sourceRoute,\n )\n if (routeWithParams !== null) {\n const applied = this.applyBaseUrl(targetLocale, routeWithParams)\n return this.preserveQueryAndHash(applied, sourceRoute)\n }\n }\n\n if (resolved.name != null) {\n const unlocalizedPath = this.getPathForUnlocalizedRoute(resolved)\n if (unlocalizedPath !== null) {\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, unlocalizedPath), sourceRoute)\n }\n // When route has custom path for target locale (globalLocaleRoutes), build path string so href is correct\n const customSegment = this.getCustomPathSegment(resolved, targetLocale)\n if (customSegment !== null) {\n const routeName = resolved.name?.toString() ?? inputName ?? ''\n const nestedInfo = routeName ? this.getNestedRouteInfo(routeName) : null\n let path: string\n if (nestedInfo) {\n const parentPath = this.getParentPathForTarget(nestedInfo.parentKey, nestedInfo.keyWithSlash, targetLocale, currentRoute)\n const segment = customSegment.startsWith('/') ? customSegment.slice(1) : customSegment\n path = joinUrl(parentPath, segment)\n }\n else {\n path = normalizePath(customSegment)\n }\n if (!this.shouldHavePrefix(targetLocale)) {\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, path), sourceRoute)\n }\n const newPath = joinUrl(targetLocale, path)\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, newPath), sourceRoute)\n }\n // Use resolved path when valid. Prefer custom path for target locale; for nested routes build parent path + custom segment.\n if (resolved.path && resolved.path !== '/' && resolved.name) {\n const { pathWithoutLocale, baseRouteName } = this.getPathWithoutLocaleAndBaseName(resolved)\n const customForTarget = this.getCustomPathSegment(resolved, targetLocale)\n const nestedInfo = baseRouteName ? this.getNestedRouteInfo(baseRouteName) : null\n const isNested = !!nestedInfo\n let pathToUse: string | null\n if (customForTarget !== null && isNested && nestedInfo) {\n const parentPath = this.getParentPathForTarget(nestedInfo.parentKey, nestedInfo.keyWithSlash, targetLocale, currentRoute)\n const segment = customForTarget.startsWith('/') ? customForTarget.slice(1) : customForTarget\n pathToUse = joinUrl(parentPath, segment)\n }\n else if (isNested && customForTarget === null && pathWithoutLocale && pathWithoutLocale !== '/' && nestedInfo) {\n const parentPath = this.getParentPathForTarget(nestedInfo.parentKey, nestedInfo.keyWithSlash, targetLocale, currentRoute)\n const segment = lastPathSegment(pathWithoutLocale)\n pathToUse = parentPath ? joinUrl(parentPath, segment) : (pathWithoutLocale !== '/' ? pathWithoutLocale : null)\n }\n else {\n pathToUse = customForTarget !== null && !isNested\n ? normalizePath(customForTarget)\n : (pathWithoutLocale && pathWithoutLocale !== '/' ? pathWithoutLocale : null)\n }\n if (pathToUse) {\n const fromLocale = this.detectLocaleFromName(resolved.name)\n const baseName = fromLocale ? this.getBaseRouteName(resolved, fromLocale) : (resolved.name ? this.getRouteBaseName(resolved) : null)\n const targetName = baseName\n ? (this.shouldHavePrefix(targetLocale) ? this.buildLocalizedName(baseName, targetLocale) : baseName.toString())\n : undefined\n const pathForLocale = this.shouldHavePrefix(targetLocale)\n ? joinUrl(targetLocale, pathToUse)\n : pathToUse\n const routeWithName: RouteLike = {\n ...(targetName ? { name: targetName } : {}),\n path: pathForLocale,\n fullPath: pathForLocale,\n params: { ...resolved.params, ...sourceRoute.params },\n query: { ...resolved.query, ...sourceRoute.query },\n hash: sourceRoute.hash ?? resolved.hash,\n }\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, routeWithName), sourceRoute)\n }\n }\n }\n // When resolved failed (e.g. router has only localized names), try getCustomPathSegment by synthetic path from inputName\n if (inputName) {\n const keyLastSlash = nameKeyLastSlash(inputName)\n const syntheticPath = '/' + keyLastSlash\n const syntheticResolved: ResolvedRouteLike = {\n name: inputName,\n path: syntheticPath,\n fullPath: syntheticPath,\n params: sourceRoute.params ?? {},\n }\n const customBySynthetic = this.getCustomPathSegment(syntheticResolved, targetLocale)\n if (customBySynthetic !== null) {\n const nestedInfo = this.getNestedRouteInfo(inputName)\n let pathNorm: string\n if (nestedInfo) {\n const parentPath = this.getParentPathForTarget(nestedInfo.parentKey, nestedInfo.keyWithSlash, targetLocale, currentRoute)\n const segment = customBySynthetic.startsWith('/') ? customBySynthetic.slice(1) : customBySynthetic\n pathNorm = joinUrl(parentPath || '/', segment)\n }\n else {\n pathNorm = normalizePath(customBySynthetic)\n }\n if (!this.shouldHavePrefix(targetLocale)) {\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, pathNorm), sourceRoute)\n }\n const newPath = joinUrl(targetLocale, pathNorm)\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, newPath), sourceRoute)\n }\n }\n if (inputName && !hasParams) {\n // For default locale, try base route name first (e.g. 'index' instead of 'localized-index')\n if (!this.shouldHavePrefix(targetLocale)) {\n // Default locale: try to resolve baseName directly\n if (this.ctx.router.hasRoute(inputName)) {\n const resolvedBase = this.ctx.router.resolve({ name: inputName, params: sourceRoute.params, query: sourceRoute.query, hash: sourceRoute.hash })\n if (resolvedBase?.path) {\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, {\n name: inputName,\n path: resolvedBase.path,\n fullPath: resolvedBase.fullPath,\n params: resolvedBase.params,\n query: resolvedBase.query ?? sourceRoute.query,\n hash: resolvedBase.hash ?? sourceRoute.hash,\n }), sourceRoute)\n }\n }\n }\n else {\n const routeByLocalizedName = this.tryResolveByLocalizedName(inputName, targetLocale, sourceRoute)\n if (routeByLocalizedName !== null) return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, routeByLocalizedName), sourceRoute)\n }\n }\n\n const fromLocale = currentRoute\n ? this.detectLocaleFromName(currentRoute.name)\n : this.detectLocaleFromName(resolved.name)\n\n const baseName = fromLocale\n ? this.getBaseRouteName(resolved, fromLocale)\n : resolved.name ?? null\n\n if (!baseName) return sourceRoute\n\n const targetName = this.shouldHavePrefix(targetLocale)\n ? this.buildLocalizedName(baseName, targetLocale)\n : baseName.toString()\n\n const pathWithoutLocale = isIndexRouteName(baseName)\n ? '/'\n : joinUrl('/', transformNameKeyToPath(baseName))\n const pathForLocale = this.shouldHavePrefix(targetLocale)\n ? joinUrl(targetLocale, pathWithoutLocale)\n : pathWithoutLocale\n const withBase = this.applyBaseUrl(targetLocale, pathForLocale)\n const pathStr = typeof withBase === 'string' ? withBase : (withBase as RouteLike).path ?? pathForLocale\n\n const newRoute: RouteLike = {\n name: targetName,\n path: pathStr,\n fullPath: pathStr,\n params: { ...resolved.params, ...sourceRoute.params },\n query: { ...resolved.query, ...sourceRoute.query },\n hash: sourceRoute.hash ?? resolved.hash,\n }\n\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, newRoute), sourceRoute)\n }\n\n override getCanonicalPath(route: ResolvedRouteLike, targetLocale: string): string | null {\n const segment = this.getCustomPathSegment(route, targetLocale)\n if (!segment) return null\n const normalized = segment.startsWith('/') ? segment : `/${segment}`\n if (!this.shouldHavePrefix(targetLocale)) {\n return cleanDoubleSlashes(normalized)\n }\n return cleanDoubleSlashes(`/${targetLocale}${normalized}`)\n }\n\n resolveLocaleFromPath(path: string): string | null {\n const { localeFromPath } = this.getPathWithoutLocale(path)\n if (localeFromPath) return localeFromPath\n return this.ctx.defaultLocale\n }\n\n getRedirect(currentPath: string, detectedLocale: string): string | null {\n const { pathWithoutLocale, localeFromPath } = this.getPathWithoutLocale(currentPath)\n const needPrefix = this.shouldHavePrefix(detectedLocale)\n\n // Unlocalized routes (globalLocaleRoutes[key] === false): redirect /locale/path to /path\n const gr = this.ctx.globalLocaleRoutes\n if (gr && localeFromPath !== null) {\n const pathKey = pathWithoutLocale === '/' ? '/' : withoutLeadingSlash(pathWithoutLocale)\n if (gr[pathWithoutLocale] === false || gr[pathKey] === false) {\n return normalizePathForCompare(pathWithoutLocale)\n }\n }\n\n if (localeFromPath !== null) {\n if (localeFromPath === this.ctx.defaultLocale) {\n return normalizePathForCompare(pathWithoutLocale)\n }\n if (localeFromPath === detectedLocale) {\n const expected = this.buildPathWithPrefix(pathWithoutLocale, detectedLocale)\n const currentPathOnly = getCleanPath(currentPath)\n return isSamePath(currentPathOnly, expected) ? null : expected\n }\n return this.buildPathWithPrefix(pathWithoutLocale, detectedLocale)\n }\n\n if (needPrefix) {\n return this.buildPathWithPrefix(pathWithoutLocale, detectedLocale)\n }\n const expectedPath = this.resolvePathForLocale(pathWithoutLocale, detectedLocale)\n const normalized = expectedPath.startsWith('/') ? expectedPath : `/${expectedPath}`\n const currentPathOnly = getCleanPath(currentPath)\n return isSamePath(currentPathOnly, normalized) ? null : normalized\n }\n\n override shouldReturn404(currentPath: string): string | null {\n const { pathWithoutLocale, localeFromPath } = this.getPathWithoutLocale(currentPath)\n\n // No locale in URL - no 404 from strategy perspective\n if (localeFromPath === null) return null\n\n // Default locale with prefix is 404 for prefix_except_default\n // e.g. /en when defaultLocale is 'en' and path is just the locale\n if (localeFromPath === this.ctx.defaultLocale && pathWithoutLocale === '/') {\n return 'Default locale should not have prefix'\n }\n\n // Delegate to base implementation for other checks\n return super.shouldReturn404(currentPath)\n }\n\n /** True if gr[key] is a locale rules object (Record<locale, path>). */\n private isLocaleRules(key: string): boolean {\n const gr = this.ctx.globalLocaleRoutes\n if (!gr || !key) return false\n const v = gr[key]\n return typeof v === 'object' && v !== null && !Array.isArray(v)\n }\n\n /**\n * For a nested route name (e.g. activity-locale-hiking), returns parent key and slash-key\n * when the route is nested (child or parent in globalLocaleRoutes). Otherwise null.\n */\n private getNestedRouteInfo(baseRouteName: string): { parentKey: string, keyWithSlash: string } | null {\n const gr = this.ctx.globalLocaleRoutes\n if (!gr) return null\n const keyLast = nameKeyLastSlash(baseRouteName)\n const keyFirst = nameKeyFirstSlash(baseRouteName)\n if (keyLast.includes('/') && this.isLocaleRules(keyLast)) {\n return { parentKey: parentKeyFromSlashKey(keyLast), keyWithSlash: keyLast }\n }\n if (keyFirst.includes('/') && this.isLocaleRules(keyFirst)) {\n return { parentKey: parentKeyFromSlashKey(keyFirst), keyWithSlash: keyFirst }\n }\n const parentLast = parentKeyFromSlashKey(keyLast)\n if (keyLast.includes('/') && parentLast && this.isLocaleRules(parentLast)) {\n return { parentKey: parentLast, keyWithSlash: keyLast }\n }\n const parentFirst = parentKeyFromSlashKey(keyFirst)\n if (keyFirst.includes('/') && parentFirst && this.isLocaleRules(parentFirst)) {\n return { parentKey: parentFirst, keyWithSlash: keyFirst }\n }\n return null\n }\n\n /** Parent path for target locale from gr or currentRoute. */\n private getParentPathForTarget(\n parentKey: string,\n keyWithSlash: string,\n targetLocale: string,\n currentRoute?: ResolvedRouteLike,\n ): string {\n const gr = this.ctx.globalLocaleRoutes\n const parentRules = (parentKey && gr?.[parentKey] && typeof gr[parentKey] === 'object' && !Array.isArray(gr[parentKey]))\n ? (gr[parentKey] as Record<string, string>)\n : null\n let parentPath = parentRules?.[targetLocale] ? normalizePath(parentRules[targetLocale]) : ''\n if (!parentPath && currentRoute?.path) {\n const curPathOnly = getCleanPath(currentRoute.path)\n const { pathWithoutLocale: curWithoutLocale } = this.getPathWithoutLocale(curPathOnly)\n parentPath = normalizePath(curWithoutLocale)\n }\n if (!parentPath) {\n const nameSegments = getPathSegments(keyWithSlash).slice(0, -1)\n parentPath = nameSegments.length ? joinUrl('/', ...nameSegments) : ''\n }\n return parentPath\n }\n\n private buildPathWithPrefix(pathWithoutLocale: string, locale: string): string {\n const resolved = this.resolvePathForLocale(pathWithoutLocale, locale)\n if (resolved === '/' || resolved === '') {\n return `/${locale}`\n }\n return joinUrl(`/${locale}`, resolved)\n }\n\n /**\n * Simple locale detector based on route name suffix.\n * Looks for known locale codes at the end of the name.\n */\n protected detectLocaleFromName(name: string | null): string | null {\n if (!name) return null\n for (const locale of this.ctx.locales) {\n if (name.endsWith(`-${locale.code}`)) {\n return locale.code\n }\n }\n return null\n }\n\n /**\n * Formats path for router.resolve.\n * prefix_except_default: add prefix only for non-default locale.\n */\n formatPathForResolve(path: string, fromLocale: string, toLocale: string): string {\n if (toLocale !== this.ctx.defaultLocale) {\n return `/${fromLocale}${path}`\n }\n return path\n }\n\n /**\n * prefix_except_default: redirect based on preferred locale.\n * Uses shouldHavePrefix to determine if locale needs prefix.\n * Also handles custom paths from globalLocaleRoutes.\n */\n getClientRedirect(currentPath: string, preferredLocale: string): string | null {\n const { pathWithoutLocale, localeFromPath } = this.getPathWithoutLocale(currentPath)\n\n // Check if route is unlocalized\n const gr = this.ctx.globalLocaleRoutes\n const pathKey = pathWithoutLocale === '/' ? '/' : withoutLeadingSlash(pathWithoutLocale)\n if (gr && (gr[pathWithoutLocale] === false || gr[pathKey] === false)) {\n return null // Unlocalized routes - no redirect\n }\n\n // URL has locale prefix - user explicitly navigated here, don't redirect\n if (localeFromPath !== null) return null\n\n // Resolve custom path for this locale\n const customPath = this.resolvePathForLocale(pathWithoutLocale, preferredLocale)\n const needsPrefix = this.shouldHavePrefix(preferredLocale)\n\n // Build target path\n let targetPath: string\n if (needsPrefix) {\n targetPath = cleanDoubleSlashes(`/${preferredLocale}${customPath.startsWith('/') ? customPath : `/${customPath}`}`)\n }\n else {\n targetPath = customPath.startsWith('/') ? customPath : `/${customPath}`\n }\n\n // Remove trailing slash (except for root)\n if (targetPath !== '/' && targetPath.endsWith('/')) {\n targetPath = targetPath.slice(0, -1)\n }\n\n // Only redirect if target differs from current\n const currentClean = getCleanPath(currentPath)\n if (isSamePath(currentClean, targetPath)) return null\n\n return targetPath\n }\n}\n\n/** Alias for Nuxt alias consumption. */\nexport { PrefixExceptDefaultPathStrategy as Strategy }\n"],"names":["PrefixExceptDefaultPathStrategy","BasePathStrategy","locale","localeObj","l","path","_isCustom","joinUrl","normalizePath","baseName","fromLocale","toLocale","route","options","targetName","nameWithSuffix","nameWithoutSuffix","i18nParams","newParams","resolved","newRoute","pathWithoutLocale","targetPath","targetLocale","normalized","currentRoute","newPath","inputName","sourceRoute","unlocalizedByName","syntheticPath","nameKeyLastSlash","syntheticResolved","customBySynthetic","nestedInfo","pathNorm","parentPath","segment","hasParams","routeResult","routeWithParams","applied","unlocalizedPath","customSegment","routeName","baseRouteName","customForTarget","isNested","pathToUse","lastPathSegment","pathForLocale","routeWithName","routeByLocalizedName","resolvedBase","isIndexRouteName","transformNameKeyToPath","withBase","pathStr","cleanDoubleSlashes","localeFromPath","currentPath","detectedLocale","needPrefix","gr","pathKey","withoutLeadingSlash","normalizePathForCompare","expected","currentPathOnly","getCleanPath","isSamePath","expectedPath","key","v","keyLast","keyFirst","nameKeyFirstSlash","parentKeyFromSlashKey","parentLast","parentFirst","parentKey","keyWithSlash","parentRules","curPathOnly","curWithoutLocale","nameSegments","getPathSegments","name","preferredLocale","customPath","needsPrefix","currentClean"],"mappings":"gIAMO,MAAMA,UAAwCC,EAAAA,gBAAiB,CAK1D,iBAAiBC,EAAyB,CAClD,GAAI,KAAK,IAAI,0BAA2B,MAAO,GAC/C,GAAIA,IAAW,KAAK,IAAI,cAAe,MAAO,GAE9C,MAAMC,EAAY,KAAK,IAAI,QAAQ,KAAKC,GAAKA,EAAE,OAASF,CAAM,EAC9D,MAAI,EAAAC,GAAW,SAAWA,GAAW,YAEvC,CAEU,mBAAmBE,EAAcH,EAAgBI,EAA4B,CACrF,OAAK,KAAK,iBAAiBJ,CAAM,EAC1BK,UAAQL,EAAQM,EAAAA,cAAcH,CAAI,CAAC,EADCG,EAAAA,cAAcH,CAAI,CAE/D,CAEU,wBAAwBI,EAAkBP,EAAwB,CAC1E,OAAK,KAAK,iBAAiBA,CAAM,EAC1B,KAAK,mBAAmBO,EAAUP,CAAM,E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AcrE,CAAU,EAAU,KAE1CA,CACT,CACF"}
|
|
1
|
+
{"version":3,"file":"prefix-except-default-strategy.cjs","sources":["../src/strategies/prefix-except-default.ts"],"sourcesContent":["import { cleanDoubleSlashes, isSamePath, withoutLeadingSlash } from 'ufo'\nimport type { NormalizedRouteInput, ResolvedRouteLike, RouteLike, SwitchLocaleOptions } from '../core/types'\nimport {\n getCleanPath,\n getPathSegments,\n joinUrl,\n lastPathSegment,\n nameKeyFirstSlash,\n nameKeyLastSlash,\n normalizePath,\n normalizePathForCompare,\n parentKeyFromSlashKey,\n transformNameKeyToPath,\n} from '../utils/path'\nimport { isIndexRouteName } from '../utils/route-name'\nimport { BasePathStrategy } from './base-strategy'\n\nexport class PrefixExceptDefaultPathStrategy extends BasePathStrategy {\n /**\n * For this strategy a prefix is required for all non-default locales.\n */\n protected shouldHavePrefix(locale: string): boolean {\n if (locale === this.ctx.defaultLocale) return false\n // When locale has baseUrl with baseDefault=true, no prefix needed (uses root on separate domain)\n const localeObj = this.ctx.locales.find((l) => l.code === locale)\n if (localeObj?.baseUrl && localeObj?.baseDefault) return false\n return true\n }\n\n protected buildLocalizedPath(path: string, locale: string, _isCustom: boolean): string {\n if (!this.shouldHavePrefix(locale)) return normalizePath(path)\n return joinUrl(locale, normalizePath(path))\n }\n\n protected buildLocalizedRouteName(baseName: string, locale: string): string {\n if (!this.shouldHavePrefix(locale)) return baseName\n return this.buildLocalizedName(baseName, locale)\n }\n\n override switchLocaleRoute(fromLocale: string, toLocale: string, route: ResolvedRouteLike, options: SwitchLocaleOptions): RouteLike | string {\n const baseName = this.getBaseRouteName(route, fromLocale)\n if (!baseName) return route\n\n // For non-default locale, try route name with locale suffix first (custom paths),\n // then without suffix (standard routes like \"localized-page\")\n let targetName: string\n if (this.shouldHavePrefix(toLocale)) {\n const nameWithSuffix = this.buildLocalizedName(baseName, toLocale)\n const nameWithoutSuffix = `${this.getLocalizedRouteNamePrefix()}${baseName}`\n targetName = this.ctx.router.hasRoute(nameWithSuffix) ? nameWithSuffix : nameWithoutSuffix\n } else {\n targetName = baseName\n }\n\n if (this.ctx.router.hasRoute(targetName)) {\n const i18nParams = options.i18nRouteParams?.[toLocale] || {}\n const newParams: Record<string, unknown> = { ...(route.params || {}), ...i18nParams }\n // Always set locale param for non-default locales because routes may have /:locale(...) in path\n if (this.shouldHavePrefix(toLocale)) {\n newParams.locale = toLocale\n } else {\n delete newParams.locale\n }\n\n // Resolve to get the actual path for applyBaseUrl\n const resolved = this.ctx.router.resolve({ name: targetName, params: newParams })\n const newRoute: RouteLike = {\n name: targetName,\n params: newParams,\n path: resolved?.path,\n fullPath: resolved?.fullPath,\n query: route.query,\n hash: route.hash,\n }\n\n return this.applyBaseUrl(toLocale, newRoute)\n }\n\n // Fallback: build path-based route\n const pathWithoutLocale = route.path?.replace(new RegExp(`^/${fromLocale}`), '') || '/'\n const targetPath = this.buildLocalizedPath(pathWithoutLocale, toLocale, false)\n return this.applyBaseUrl(toLocale, { path: targetPath, query: route.query, hash: route.hash })\n }\n\n protected override resolveLocaleRoute(\n targetLocale: string,\n normalized: NormalizedRouteInput,\n currentRoute?: ResolvedRouteLike,\n ): RouteLike | string {\n if (normalized.kind === 'path') {\n const path = this.resolvePathForLocale(normalized.path, targetLocale)\n if (!this.shouldHavePrefix(targetLocale)) return this.applyBaseUrl(targetLocale, path)\n const newPath = joinUrl(targetLocale, path)\n return this.applyBaseUrl(targetLocale, newPath)\n }\n\n const { inputName, sourceRoute, resolved } = normalized\n if (inputName) {\n const unlocalizedByName = this.getPathForUnlocalizedRouteByName(inputName)\n if (unlocalizedByName !== null) return this.preserveQueryAndHash(unlocalizedByName, sourceRoute)\n const keyLastSlash = nameKeyLastSlash(inputName)\n const syntheticPath = `/${keyLastSlash}`\n const syntheticResolved: ResolvedRouteLike = {\n name: inputName,\n path: syntheticPath,\n fullPath: syntheticPath,\n params: sourceRoute.params ?? {},\n }\n const customBySynthetic = this.getCustomPathSegment(syntheticResolved, targetLocale)\n if (customBySynthetic !== null) {\n const nestedInfo = this.getNestedRouteInfo(inputName)\n let pathNorm: string\n if (nestedInfo) {\n const parentPath = this.getParentPathForTarget(nestedInfo.parentKey, nestedInfo.keyWithSlash, targetLocale, currentRoute)\n const segment = customBySynthetic.startsWith('/') ? customBySynthetic.slice(1) : customBySynthetic\n pathNorm = parentPath ? joinUrl(parentPath, segment) : normalizePath(customBySynthetic)\n } else {\n pathNorm = normalizePath(customBySynthetic)\n }\n if (!this.shouldHavePrefix(targetLocale)) {\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, pathNorm), sourceRoute)\n }\n const newPath = joinUrl(targetLocale, pathNorm)\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, newPath), sourceRoute)\n }\n }\n\n const hasParams = sourceRoute.params && Object.keys(sourceRoute.params ?? {}).length > 0\n if (inputName && hasParams) {\n // For default locale, try resolving base route name first (without localized prefix)\n if (!this.shouldHavePrefix(targetLocale) && this.ctx.router.hasRoute(inputName)) {\n const resolved = this.ctx.router.resolve({\n name: inputName,\n params: sourceRoute.params,\n query: sourceRoute.query,\n hash: sourceRoute.hash,\n })\n if (resolved?.path && resolved.path !== '/') {\n const routeResult: RouteLike = {\n name: inputName,\n path: resolved.path,\n fullPath: resolved.fullPath,\n params: resolved.params,\n query: resolved.query ?? sourceRoute.query,\n hash: resolved.hash ?? sourceRoute.hash,\n }\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, routeResult), sourceRoute)\n }\n }\n const routeWithParams = this.tryResolveByLocalizedNameWithParams(inputName, targetLocale, sourceRoute.params ?? {}, sourceRoute)\n if (routeWithParams !== null) {\n const applied = this.applyBaseUrl(targetLocale, routeWithParams)\n return this.preserveQueryAndHash(applied, sourceRoute)\n }\n }\n\n if (resolved.name != null) {\n const unlocalizedPath = this.getPathForUnlocalizedRoute(resolved)\n if (unlocalizedPath !== null) {\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, unlocalizedPath), sourceRoute)\n }\n // When route has custom path for target locale (globalLocaleRoutes), build path string so href is correct\n const customSegment = this.getCustomPathSegment(resolved, targetLocale)\n if (customSegment !== null) {\n const routeName = resolved.name?.toString() ?? inputName ?? ''\n const nestedInfo = routeName ? this.getNestedRouteInfo(routeName) : null\n let path: string\n if (nestedInfo) {\n const parentPath = this.getParentPathForTarget(nestedInfo.parentKey, nestedInfo.keyWithSlash, targetLocale, currentRoute)\n const segment = customSegment.startsWith('/') ? customSegment.slice(1) : customSegment\n path = joinUrl(parentPath, segment)\n } else {\n path = normalizePath(customSegment)\n }\n if (!this.shouldHavePrefix(targetLocale)) {\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, path), sourceRoute)\n }\n const newPath = joinUrl(targetLocale, path)\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, newPath), sourceRoute)\n }\n // Use resolved path when valid. Prefer custom path for target locale; for nested routes build parent path + custom segment.\n if (resolved.path && resolved.path !== '/' && resolved.name) {\n const { pathWithoutLocale, baseRouteName } = this.getPathWithoutLocaleAndBaseName(resolved)\n const customForTarget = this.getCustomPathSegment(resolved, targetLocale)\n const nestedInfo = baseRouteName ? this.getNestedRouteInfo(baseRouteName) : null\n const isNested = !!nestedInfo\n let pathToUse: string | null\n if (customForTarget !== null && isNested && nestedInfo) {\n const parentPath = this.getParentPathForTarget(nestedInfo.parentKey, nestedInfo.keyWithSlash, targetLocale, currentRoute)\n const segment = customForTarget.startsWith('/') ? customForTarget.slice(1) : customForTarget\n pathToUse = joinUrl(parentPath, segment)\n } else if (isNested && customForTarget === null && pathWithoutLocale && pathWithoutLocale !== '/' && nestedInfo) {\n const parentPath = this.getParentPathForTarget(nestedInfo.parentKey, nestedInfo.keyWithSlash, targetLocale, currentRoute)\n const segment = lastPathSegment(pathWithoutLocale)\n pathToUse = parentPath ? joinUrl(parentPath, segment) : pathWithoutLocale !== '/' ? pathWithoutLocale : null\n } else {\n pathToUse =\n customForTarget !== null && !isNested\n ? normalizePath(customForTarget)\n : pathWithoutLocale && pathWithoutLocale !== '/'\n ? pathWithoutLocale\n : null\n }\n if (pathToUse) {\n const fromLocale = this.detectLocaleFromName(resolved.name)\n const baseName = fromLocale ? this.getBaseRouteName(resolved, fromLocale) : resolved.name ? this.getRouteBaseName(resolved) : null\n const targetName = baseName\n ? this.shouldHavePrefix(targetLocale)\n ? this.buildLocalizedName(baseName, targetLocale)\n : baseName.toString()\n : undefined\n const pathForLocale = this.shouldHavePrefix(targetLocale) ? joinUrl(targetLocale, pathToUse) : pathToUse\n const routeWithName: RouteLike = {\n ...(targetName ? { name: targetName } : {}),\n path: pathForLocale,\n fullPath: pathForLocale,\n params: { ...resolved.params, ...sourceRoute.params },\n query: { ...resolved.query, ...sourceRoute.query },\n hash: sourceRoute.hash ?? resolved.hash,\n }\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, routeWithName), sourceRoute)\n }\n }\n }\n // When resolved failed (e.g. router has only localized names), try getCustomPathSegment by synthetic path from inputName\n if (inputName) {\n const keyLastSlash = nameKeyLastSlash(inputName)\n const syntheticPath = `/${keyLastSlash}`\n const syntheticResolved: ResolvedRouteLike = {\n name: inputName,\n path: syntheticPath,\n fullPath: syntheticPath,\n params: sourceRoute.params ?? {},\n }\n const customBySynthetic = this.getCustomPathSegment(syntheticResolved, targetLocale)\n if (customBySynthetic !== null) {\n const nestedInfo = this.getNestedRouteInfo(inputName)\n let pathNorm: string\n if (nestedInfo) {\n const parentPath = this.getParentPathForTarget(nestedInfo.parentKey, nestedInfo.keyWithSlash, targetLocale, currentRoute)\n const segment = customBySynthetic.startsWith('/') ? customBySynthetic.slice(1) : customBySynthetic\n pathNorm = joinUrl(parentPath || '/', segment)\n } else {\n pathNorm = normalizePath(customBySynthetic)\n }\n if (!this.shouldHavePrefix(targetLocale)) {\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, pathNorm), sourceRoute)\n }\n const newPath = joinUrl(targetLocale, pathNorm)\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, newPath), sourceRoute)\n }\n }\n if (inputName && !hasParams) {\n // For default locale, try base route name first (e.g. 'index' instead of 'localized-index')\n if (!this.shouldHavePrefix(targetLocale)) {\n // Default locale: try to resolve baseName directly\n if (this.ctx.router.hasRoute(inputName)) {\n const resolvedBase = this.ctx.router.resolve({\n name: inputName,\n params: sourceRoute.params,\n query: sourceRoute.query,\n hash: sourceRoute.hash,\n })\n if (resolvedBase?.path) {\n return this.preserveQueryAndHash(\n this.applyBaseUrl(targetLocale, {\n name: inputName,\n path: resolvedBase.path,\n fullPath: resolvedBase.fullPath,\n params: resolvedBase.params,\n query: resolvedBase.query ?? sourceRoute.query,\n hash: resolvedBase.hash ?? sourceRoute.hash,\n }),\n sourceRoute,\n )\n }\n }\n } else {\n const routeByLocalizedName = this.tryResolveByLocalizedName(inputName, targetLocale, sourceRoute)\n if (routeByLocalizedName !== null) return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, routeByLocalizedName), sourceRoute)\n }\n }\n\n const fromLocale = currentRoute ? this.detectLocaleFromName(currentRoute.name) : this.detectLocaleFromName(resolved.name)\n\n const baseName = fromLocale ? this.getBaseRouteName(resolved, fromLocale) : (resolved.name ?? null)\n\n if (!baseName) return sourceRoute\n\n const targetName = this.shouldHavePrefix(targetLocale) ? this.buildLocalizedName(baseName, targetLocale) : baseName.toString()\n\n const pathWithoutLocale = isIndexRouteName(baseName) ? '/' : joinUrl('/', transformNameKeyToPath(baseName))\n const pathForLocale = this.shouldHavePrefix(targetLocale) ? joinUrl(targetLocale, pathWithoutLocale) : pathWithoutLocale\n const withBase = this.applyBaseUrl(targetLocale, pathForLocale)\n const pathStr = typeof withBase === 'string' ? withBase : ((withBase as RouteLike).path ?? pathForLocale)\n\n const newRoute: RouteLike = {\n name: targetName,\n path: pathStr,\n fullPath: pathStr,\n params: { ...resolved.params, ...sourceRoute.params },\n query: { ...resolved.query, ...sourceRoute.query },\n hash: sourceRoute.hash ?? resolved.hash,\n }\n\n return this.preserveQueryAndHash(this.applyBaseUrl(targetLocale, newRoute), sourceRoute)\n }\n\n override getCanonicalPath(route: ResolvedRouteLike, targetLocale: string): string | null {\n const segment = this.getCustomPathSegment(route, targetLocale)\n if (!segment) return null\n const normalized = segment.startsWith('/') ? segment : `/${segment}`\n if (!this.shouldHavePrefix(targetLocale)) {\n return cleanDoubleSlashes(normalized)\n }\n return cleanDoubleSlashes(`/${targetLocale}${normalized}`)\n }\n\n resolveLocaleFromPath(path: string): string | null {\n const { localeFromPath } = this.getPathWithoutLocale(path)\n if (localeFromPath) return localeFromPath\n return this.ctx.defaultLocale\n }\n\n getRedirect(currentPath: string, detectedLocale: string): string | null {\n const { pathWithoutLocale, localeFromPath } = this.getPathWithoutLocale(currentPath)\n const needPrefix = this.shouldHavePrefix(detectedLocale)\n\n // Unlocalized routes (globalLocaleRoutes[key] === false): redirect /locale/path to /path\n const gr = this.ctx.globalLocaleRoutes\n if (gr && localeFromPath !== null) {\n const pathKey = pathWithoutLocale === '/' ? '/' : withoutLeadingSlash(pathWithoutLocale)\n if (gr[pathWithoutLocale] === false || gr[pathKey] === false) {\n return normalizePathForCompare(pathWithoutLocale)\n }\n }\n\n if (localeFromPath !== null) {\n if (localeFromPath === this.ctx.defaultLocale) {\n return normalizePathForCompare(pathWithoutLocale)\n }\n if (localeFromPath === detectedLocale) {\n const expected = this.buildPathWithPrefix(pathWithoutLocale, detectedLocale)\n const currentPathOnly = getCleanPath(currentPath)\n return isSamePath(currentPathOnly, expected) ? null : expected\n }\n return this.buildPathWithPrefix(pathWithoutLocale, detectedLocale)\n }\n\n if (needPrefix) {\n return this.buildPathWithPrefix(pathWithoutLocale, detectedLocale)\n }\n const expectedPath = this.resolvePathForLocale(pathWithoutLocale, detectedLocale)\n const normalized = expectedPath.startsWith('/') ? expectedPath : `/${expectedPath}`\n const currentPathOnly = getCleanPath(currentPath)\n return isSamePath(currentPathOnly, normalized) ? null : normalized\n }\n\n override shouldReturn404(currentPath: string): string | null {\n const { pathWithoutLocale, localeFromPath } = this.getPathWithoutLocale(currentPath)\n\n // No locale in URL - no 404 from strategy perspective\n if (localeFromPath === null) return null\n\n // Default locale with prefix is 404 for prefix_except_default\n // e.g. /en when defaultLocale is 'en' and path is just the locale\n if (localeFromPath === this.ctx.defaultLocale && pathWithoutLocale === '/') {\n return 'Default locale should not have prefix'\n }\n\n // Delegate to base implementation for other checks\n return super.shouldReturn404(currentPath)\n }\n\n /** True if gr[key] is a locale rules object (Record<locale, path>). */\n private isLocaleRules(key: string): boolean {\n const gr = this.ctx.globalLocaleRoutes\n if (!gr || !key) return false\n const v = gr[key]\n return typeof v === 'object' && v !== null && !Array.isArray(v)\n }\n\n /**\n * For a nested route name (e.g. activity-locale-hiking), returns parent key and slash-key\n * when the route is nested (child or parent in globalLocaleRoutes). Otherwise null.\n */\n private getNestedRouteInfo(baseRouteName: string): { parentKey: string; keyWithSlash: string } | null {\n const gr = this.ctx.globalLocaleRoutes\n if (!gr) return null\n const keyLast = nameKeyLastSlash(baseRouteName)\n const keyFirst = nameKeyFirstSlash(baseRouteName)\n if (keyLast.includes('/') && this.isLocaleRules(keyLast)) {\n return { parentKey: parentKeyFromSlashKey(keyLast), keyWithSlash: keyLast }\n }\n if (keyFirst.includes('/') && this.isLocaleRules(keyFirst)) {\n return { parentKey: parentKeyFromSlashKey(keyFirst), keyWithSlash: keyFirst }\n }\n const parentLast = parentKeyFromSlashKey(keyLast)\n if (keyLast.includes('/') && parentLast && this.isLocaleRules(parentLast)) {\n return { parentKey: parentLast, keyWithSlash: keyLast }\n }\n const parentFirst = parentKeyFromSlashKey(keyFirst)\n if (keyFirst.includes('/') && parentFirst && this.isLocaleRules(parentFirst)) {\n return { parentKey: parentFirst, keyWithSlash: keyFirst }\n }\n return null\n }\n\n /** Parent path for target locale from gr or currentRoute. */\n private getParentPathForTarget(parentKey: string, keyWithSlash: string, targetLocale: string, currentRoute?: ResolvedRouteLike): string {\n const gr = this.ctx.globalLocaleRoutes\n const parentRules =\n parentKey && gr?.[parentKey] && typeof gr[parentKey] === 'object' && !Array.isArray(gr[parentKey])\n ? (gr[parentKey] as Record<string, string>)\n : null\n let parentPath = parentRules?.[targetLocale] ? normalizePath(parentRules[targetLocale]) : ''\n if (!parentPath && currentRoute?.path) {\n const curPathOnly = getCleanPath(currentRoute.path)\n const { pathWithoutLocale: curWithoutLocale } = this.getPathWithoutLocale(curPathOnly)\n parentPath = normalizePath(curWithoutLocale)\n }\n if (!parentPath) {\n const nameSegments = getPathSegments(keyWithSlash).slice(0, -1)\n parentPath = nameSegments.length ? joinUrl('/', ...nameSegments) : ''\n }\n return parentPath\n }\n\n private buildPathWithPrefix(pathWithoutLocale: string, locale: string): string {\n const resolved = this.resolvePathForLocale(pathWithoutLocale, locale)\n if (resolved === '/' || resolved === '') {\n return `/${locale}`\n }\n return joinUrl(`/${locale}`, resolved)\n }\n\n /**\n * Simple locale detector based on route name suffix.\n * Looks for known locale codes at the end of the name.\n */\n protected detectLocaleFromName(name: string | null): string | null {\n if (!name) return null\n for (const locale of this.ctx.locales) {\n if (name.endsWith(`-${locale.code}`)) {\n return locale.code\n }\n }\n return null\n }\n\n /**\n * Formats path for router.resolve.\n * prefix_except_default: add prefix only for non-default locale.\n */\n formatPathForResolve(path: string, fromLocale: string, toLocale: string): string {\n if (toLocale !== this.ctx.defaultLocale) {\n return `/${fromLocale}${path}`\n }\n return path\n }\n\n /**\n * prefix_except_default: redirect based on preferred locale.\n * Uses shouldHavePrefix to determine if locale needs prefix.\n * Also handles custom paths from globalLocaleRoutes.\n */\n getClientRedirect(currentPath: string, preferredLocale: string): string | null {\n const { pathWithoutLocale, localeFromPath } = this.getPathWithoutLocale(currentPath)\n\n // Check if route is unlocalized\n const gr = this.ctx.globalLocaleRoutes\n const pathKey = pathWithoutLocale === '/' ? '/' : withoutLeadingSlash(pathWithoutLocale)\n if (gr && (gr[pathWithoutLocale] === false || gr[pathKey] === false)) {\n return null // Unlocalized routes - no redirect\n }\n\n // URL has locale prefix - user explicitly navigated here, don't redirect\n if (localeFromPath !== null) return null\n\n // Resolve custom path for this locale\n const customPath = this.resolvePathForLocale(pathWithoutLocale, preferredLocale)\n const needsPrefix = this.shouldHavePrefix(preferredLocale)\n\n // Build target path\n let targetPath: string\n if (needsPrefix) {\n targetPath = cleanDoubleSlashes(`/${preferredLocale}${customPath.startsWith('/') ? customPath : `/${customPath}`}`)\n } else {\n targetPath = customPath.startsWith('/') ? customPath : `/${customPath}`\n }\n\n // Remove trailing slash (except for root)\n if (targetPath !== '/' && targetPath.endsWith('/')) {\n targetPath = targetPath.slice(0, -1)\n }\n\n // Only redirect if target differs from current\n const currentClean = getCleanPath(currentPath)\n if (isSamePath(currentClean, targetPath)) return null\n\n return targetPath\n }\n}\n\n/** Alias for Nuxt alias consumption. */\nexport { PrefixExceptDefaultPathStrategy as Strategy }\n"],"names":["PrefixExceptDefaultPathStrategy","BasePathStrategy","locale","localeObj","l","path","_isCustom","joinUrl","normalizePath","baseName","fromLocale","toLocale","route","options","targetName","nameWithSuffix","nameWithoutSuffix","i18nParams","newParams","resolved","newRoute","pathWithoutLocale","targetPath","targetLocale","normalized","currentRoute","newPath","inputName","sourceRoute","unlocalizedByName","syntheticPath","nameKeyLastSlash","syntheticResolved","customBySynthetic","nestedInfo","pathNorm","parentPath","segment","hasParams","routeResult","routeWithParams","applied","unlocalizedPath","customSegment","routeName","baseRouteName","customForTarget","isNested","pathToUse","lastPathSegment","pathForLocale","routeWithName","routeByLocalizedName","resolvedBase","isIndexRouteName","transformNameKeyToPath","withBase","pathStr","cleanDoubleSlashes","localeFromPath","currentPath","detectedLocale","needPrefix","gr","pathKey","withoutLeadingSlash","normalizePathForCompare","expected","currentPathOnly","getCleanPath","isSamePath","expectedPath","key","v","keyLast","keyFirst","nameKeyFirstSlash","parentKeyFromSlashKey","parentLast","parentFirst","parentKey","keyWithSlash","parentRules","curPathOnly","curWithoutLocale","nameSegments","getPathSegments","name","preferredLocale","customPath","needsPrefix","currentClean"],"mappings":"gIAiBO,MAAMA,UAAwCC,EAAAA,g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C,CAAO,IAAM,KAK1DL,IAAmB,KAAM,OAAO,KAGpC,MAAM8B,EAAa,KAAK,qBAAqBpE,EAAmBmE,CAAe,EACzEE,EAAc,KAAK,iBAAiBF,CAAe,EAGzD,IAAIlE,EACAoE,EACFpE,EAAaoC,EAAAA,mBAAmB,IAAI8B,CAAe,GAAGC,EAAW,WAAW,GAAG,EAAIA,EAAa,IAAIA,CAAU,EAAE,EAAE,EAElHnE,EAAamE,EAAW,WAAW,GAAG,EAAIA,EAAa,IAAIA,CAAU,GAInEnE,IAAe,KAAOA,EAAW,SAAS,GAAG,IAC/CA,EAAaA,EAAW,MAAM,EAAG,EAAE,GAIrC,MAAMqE,EAAetB,EAAAA,aAAaT,CAAW,EAC7C,OAAIU,aAAWqB,EAAcrE,CAAU,EAAU,KAE1CA,CACT,CACF"}
|
|
@@ -260,7 +260,6 @@ declare interface PathStrategyContext {
|
|
|
260
260
|
globalLocaleRoutes?: GlobalLocaleRoutes;
|
|
261
261
|
routeLocales?: Record<string, string[]>;
|
|
262
262
|
routesLocaleLinks?: Record<string, string>;
|
|
263
|
-
includeDefaultLocaleRoute?: boolean;
|
|
264
263
|
noPrefixRedirect?: boolean;
|
|
265
264
|
debug?: boolean;
|
|
266
265
|
router: RouterAdapter;
|
|
@@ -272,8 +271,7 @@ declare interface PathStrategyContext {
|
|
|
272
271
|
|
|
273
272
|
declare class PrefixExceptDefaultPathStrategy extends BasePathStrategy {
|
|
274
273
|
/**
|
|
275
|
-
* For this strategy a prefix is required for all non-default locales
|
|
276
|
-
* unless includeDefaultLocaleRoute is explicitly enabled.
|
|
274
|
+
* For this strategy a prefix is required for all non-default locales.
|
|
277
275
|
*/
|
|
278
276
|
protected shouldHavePrefix(locale: string): boolean;
|
|
279
277
|
protected buildLocalizedPath(path: string, locale: string, _isCustom: boolean): string;
|
|
@@ -342,7 +340,7 @@ declare class RouteResolver {
|
|
|
342
340
|
constructor(ctx: PathStrategyContext);
|
|
343
341
|
/**
|
|
344
342
|
* Substitutes params into path template (:key, :key(), [...key]).
|
|
345
|
-
* Uses
|
|
343
|
+
* Uses a single pre-compiled regex for all keys in one pass — no per-key RegExp allocation.
|
|
346
344
|
*/
|
|
347
345
|
resolvePathWithParams(path: string, params?: Record<string, unknown>): string;
|
|
348
346
|
/**
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { B as K, n as R, j as m, b as F, l as C, d as I, t as T, c as b, w as
|
|
1
|
+
import { B as K, n as R, j as m, b as F, l as C, d as I, t as T, c as b, w as z, a as k, g, i as U, e as j, p as B, f as O } from "./base-strategy-DmOQzfP1.js";
|
|
2
2
|
class L extends K {
|
|
3
3
|
/**
|
|
4
|
-
* For this strategy a prefix is required for all non-default locales
|
|
5
|
-
* unless includeDefaultLocaleRoute is explicitly enabled.
|
|
4
|
+
* For this strategy a prefix is required for all non-default locales.
|
|
6
5
|
*/
|
|
7
6
|
shouldHavePrefix(t) {
|
|
8
|
-
if (this.ctx.includeDefaultLocaleRoute) return !0;
|
|
9
7
|
if (t === this.ctx.defaultLocale) return !1;
|
|
10
8
|
const a = this.ctx.locales.find((e) => e.code === t);
|
|
11
9
|
return !(a?.baseUrl && a?.baseDefault);
|
|
@@ -21,16 +19,16 @@ class L extends K {
|
|
|
21
19
|
if (!s) return e;
|
|
22
20
|
let r;
|
|
23
21
|
if (this.shouldHavePrefix(a)) {
|
|
24
|
-
const i = this.buildLocalizedName(s, a),
|
|
25
|
-
r = this.ctx.router.hasRoute(i) ? i :
|
|
22
|
+
const i = this.buildLocalizedName(s, a), f = `${this.getLocalizedRouteNamePrefix()}${s}`;
|
|
23
|
+
r = this.ctx.router.hasRoute(i) ? i : f;
|
|
26
24
|
} else
|
|
27
25
|
r = s;
|
|
28
26
|
if (this.ctx.router.hasRoute(r)) {
|
|
29
|
-
const i = h.i18nRouteParams?.[a] || {},
|
|
30
|
-
this.shouldHavePrefix(a) ?
|
|
31
|
-
const S = this.ctx.router.resolve({ name: r, params:
|
|
27
|
+
const i = h.i18nRouteParams?.[a] || {}, f = { ...e.params || {}, ...i };
|
|
28
|
+
this.shouldHavePrefix(a) ? f.locale = a : delete f.locale;
|
|
29
|
+
const S = this.ctx.router.resolve({ name: r, params: f }), N = {
|
|
32
30
|
name: r,
|
|
33
|
-
params:
|
|
31
|
+
params: f,
|
|
34
32
|
path: S?.path,
|
|
35
33
|
fullPath: S?.fullPath,
|
|
36
34
|
query: e.query,
|
|
@@ -52,17 +50,17 @@ class L extends K {
|
|
|
52
50
|
if (h) {
|
|
53
51
|
const l = this.getPathForUnlocalizedRouteByName(h);
|
|
54
52
|
if (l !== null) return this.preserveQueryAndHash(l, s);
|
|
55
|
-
const c =
|
|
53
|
+
const c = `/${F(h)}`, y = {
|
|
56
54
|
name: h,
|
|
57
55
|
path: c,
|
|
58
56
|
fullPath: c,
|
|
59
57
|
params: s.params ?? {}
|
|
60
58
|
}, n = this.getCustomPathSegment(y, t);
|
|
61
59
|
if (n !== null) {
|
|
62
|
-
const
|
|
60
|
+
const p = this.getNestedRouteInfo(h);
|
|
63
61
|
let d;
|
|
64
|
-
if (
|
|
65
|
-
const v = this.getParentPathForTarget(
|
|
62
|
+
if (p) {
|
|
63
|
+
const v = this.getParentPathForTarget(p.parentKey, p.keyWithSlash, t, e), W = n.startsWith("/") ? n.slice(1) : n;
|
|
66
64
|
d = v ? m(v, W) : R(n);
|
|
67
65
|
} else
|
|
68
66
|
d = R(n);
|
|
@@ -93,12 +91,7 @@ class L extends K {
|
|
|
93
91
|
return this.preserveQueryAndHash(this.applyBaseUrl(t, c), s);
|
|
94
92
|
}
|
|
95
93
|
}
|
|
96
|
-
const l = this.tryResolveByLocalizedNameWithParams(
|
|
97
|
-
h,
|
|
98
|
-
t,
|
|
99
|
-
s.params ?? {},
|
|
100
|
-
s
|
|
101
|
-
);
|
|
94
|
+
const l = this.tryResolveByLocalizedNameWithParams(h, t, s.params ?? {}, s);
|
|
102
95
|
if (l !== null) {
|
|
103
96
|
const u = this.applyBaseUrl(t, l);
|
|
104
97
|
return this.preserveQueryAndHash(u, s);
|
|
@@ -119,25 +112,25 @@ class L extends K {
|
|
|
119
112
|
n = R(u);
|
|
120
113
|
if (!this.shouldHavePrefix(t))
|
|
121
114
|
return this.preserveQueryAndHash(this.applyBaseUrl(t, n), s);
|
|
122
|
-
const
|
|
123
|
-
return this.preserveQueryAndHash(this.applyBaseUrl(t,
|
|
115
|
+
const p = m(t, n);
|
|
116
|
+
return this.preserveQueryAndHash(this.applyBaseUrl(t, p), s);
|
|
124
117
|
}
|
|
125
118
|
if (r.path && r.path !== "/" && r.name) {
|
|
126
|
-
const { pathWithoutLocale: c, baseRouteName: y } = this.getPathWithoutLocaleAndBaseName(r), n = this.getCustomPathSegment(r, t),
|
|
119
|
+
const { pathWithoutLocale: c, baseRouteName: y } = this.getPathWithoutLocaleAndBaseName(r), n = this.getCustomPathSegment(r, t), p = y ? this.getNestedRouteInfo(y) : null, d = !!p;
|
|
127
120
|
let x;
|
|
128
|
-
if (n !== null && d &&
|
|
129
|
-
const v = this.getParentPathForTarget(
|
|
121
|
+
if (n !== null && d && p) {
|
|
122
|
+
const v = this.getParentPathForTarget(p.parentKey, p.keyWithSlash, t, e), W = n.startsWith("/") ? n.slice(1) : n;
|
|
130
123
|
x = m(v, W);
|
|
131
|
-
} else if (d && n === null && c && c !== "/" &&
|
|
132
|
-
const v = this.getParentPathForTarget(
|
|
124
|
+
} else if (d && n === null && c && c !== "/" && p) {
|
|
125
|
+
const v = this.getParentPathForTarget(p.parentKey, p.keyWithSlash, t, e), W = C(c);
|
|
133
126
|
x = v ? m(v, W) : c !== "/" ? c : null;
|
|
134
127
|
} else
|
|
135
128
|
x = n !== null && !d ? R(n) : c && c !== "/" ? c : null;
|
|
136
129
|
if (x) {
|
|
137
|
-
const v = this.detectLocaleFromName(r.name), W = v ? this.getBaseRouteName(r, v) : r.name ? this.getRouteBaseName(r) : null, A = W ? this.shouldHavePrefix(t) ? this.buildLocalizedName(W, t) : W.toString() : void 0,
|
|
130
|
+
const v = this.detectLocaleFromName(r.name), W = v ? this.getBaseRouteName(r, v) : r.name ? this.getRouteBaseName(r) : null, A = W ? this.shouldHavePrefix(t) ? this.buildLocalizedName(W, t) : W.toString() : void 0, $ = this.shouldHavePrefix(t) ? m(t, x) : x, w = {
|
|
138
131
|
...A ? { name: A } : {},
|
|
139
|
-
path:
|
|
140
|
-
fullPath:
|
|
132
|
+
path: $,
|
|
133
|
+
fullPath: $,
|
|
141
134
|
params: { ...r.params, ...s.params },
|
|
142
135
|
query: { ...r.query, ...s.query },
|
|
143
136
|
hash: s.hash ?? r.hash
|
|
@@ -147,7 +140,7 @@ class L extends K {
|
|
|
147
140
|
}
|
|
148
141
|
}
|
|
149
142
|
if (h) {
|
|
150
|
-
const u =
|
|
143
|
+
const u = `/${F(h)}`, c = {
|
|
151
144
|
name: h,
|
|
152
145
|
path: u,
|
|
153
146
|
fullPath: u,
|
|
@@ -155,15 +148,15 @@ class L extends K {
|
|
|
155
148
|
}, y = this.getCustomPathSegment(c, t);
|
|
156
149
|
if (y !== null) {
|
|
157
150
|
const n = this.getNestedRouteInfo(h);
|
|
158
|
-
let
|
|
151
|
+
let p;
|
|
159
152
|
if (n) {
|
|
160
153
|
const x = this.getParentPathForTarget(n.parentKey, n.keyWithSlash, t, e), v = y.startsWith("/") ? y.slice(1) : y;
|
|
161
|
-
|
|
154
|
+
p = m(x || "/", v);
|
|
162
155
|
} else
|
|
163
|
-
|
|
156
|
+
p = R(y);
|
|
164
157
|
if (!this.shouldHavePrefix(t))
|
|
165
|
-
return this.preserveQueryAndHash(this.applyBaseUrl(t,
|
|
166
|
-
const d = m(t,
|
|
158
|
+
return this.preserveQueryAndHash(this.applyBaseUrl(t, p), s);
|
|
159
|
+
const d = m(t, p);
|
|
167
160
|
return this.preserveQueryAndHash(this.applyBaseUrl(t, d), s);
|
|
168
161
|
}
|
|
169
162
|
}
|
|
@@ -172,22 +165,30 @@ class L extends K {
|
|
|
172
165
|
const l = this.tryResolveByLocalizedName(h, t, s);
|
|
173
166
|
if (l !== null) return this.preserveQueryAndHash(this.applyBaseUrl(t, l), s);
|
|
174
167
|
} else if (this.ctx.router.hasRoute(h)) {
|
|
175
|
-
const l = this.ctx.router.resolve({
|
|
168
|
+
const l = this.ctx.router.resolve({
|
|
169
|
+
name: h,
|
|
170
|
+
params: s.params,
|
|
171
|
+
query: s.query,
|
|
172
|
+
hash: s.hash
|
|
173
|
+
});
|
|
176
174
|
if (l?.path)
|
|
177
|
-
return this.preserveQueryAndHash(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
175
|
+
return this.preserveQueryAndHash(
|
|
176
|
+
this.applyBaseUrl(t, {
|
|
177
|
+
name: h,
|
|
178
|
+
path: l.path,
|
|
179
|
+
fullPath: l.fullPath,
|
|
180
|
+
params: l.params,
|
|
181
|
+
query: l.query ?? s.query,
|
|
182
|
+
hash: l.hash ?? s.hash
|
|
183
|
+
}),
|
|
184
|
+
s
|
|
185
|
+
);
|
|
185
186
|
}
|
|
186
187
|
}
|
|
187
188
|
const P = e ? this.detectLocaleFromName(e.name) : this.detectLocaleFromName(r.name), i = P ? this.getBaseRouteName(r, P) : r.name ?? null;
|
|
188
189
|
if (!i) return s;
|
|
189
|
-
const
|
|
190
|
-
name:
|
|
190
|
+
const f = this.shouldHavePrefix(t) ? this.buildLocalizedName(i, t) : i.toString(), S = I(i) ? "/" : m("/", T(i)), N = this.shouldHavePrefix(t) ? m(t, S) : S, H = this.applyBaseUrl(t, N), q = typeof H == "string" ? H : H.path ?? N, Q = {
|
|
191
|
+
name: f,
|
|
191
192
|
path: q,
|
|
192
193
|
fullPath: q,
|
|
193
194
|
params: { ...r.params, ...s.params },
|
|
@@ -209,16 +210,16 @@ class L extends K {
|
|
|
209
210
|
getRedirect(t, a) {
|
|
210
211
|
const { pathWithoutLocale: e, localeFromPath: h } = this.getPathWithoutLocale(t), s = this.shouldHavePrefix(a), r = this.ctx.globalLocaleRoutes;
|
|
211
212
|
if (r && h !== null) {
|
|
212
|
-
const
|
|
213
|
-
if (r[e] === !1 || r[
|
|
214
|
-
return
|
|
213
|
+
const f = e === "/" ? "/" : z(e);
|
|
214
|
+
if (r[e] === !1 || r[f] === !1)
|
|
215
|
+
return k(e);
|
|
215
216
|
}
|
|
216
217
|
if (h !== null) {
|
|
217
218
|
if (h === this.ctx.defaultLocale)
|
|
218
|
-
return
|
|
219
|
+
return k(e);
|
|
219
220
|
if (h === a) {
|
|
220
|
-
const
|
|
221
|
-
return U(S,
|
|
221
|
+
const f = this.buildPathWithPrefix(e, a), S = g(t);
|
|
222
|
+
return U(S, f) ? null : f;
|
|
222
223
|
}
|
|
223
224
|
return this.buildPathWithPrefix(e, a);
|
|
224
225
|
}
|
|
@@ -264,7 +265,7 @@ class L extends K {
|
|
|
264
265
|
o = R(i);
|
|
265
266
|
}
|
|
266
267
|
if (!o) {
|
|
267
|
-
const P =
|
|
268
|
+
const P = O(a).slice(0, -1);
|
|
268
269
|
o = P.length ? m("/", ...P) : "";
|
|
269
270
|
}
|
|
270
271
|
return o;
|
|
@@ -297,13 +298,13 @@ class L extends K {
|
|
|
297
298
|
* Also handles custom paths from globalLocaleRoutes.
|
|
298
299
|
*/
|
|
299
300
|
getClientRedirect(t, a) {
|
|
300
|
-
const { pathWithoutLocale: e, localeFromPath: h } = this.getPathWithoutLocale(t), s = this.ctx.globalLocaleRoutes, r = e === "/" ? "/" :
|
|
301
|
+
const { pathWithoutLocale: e, localeFromPath: h } = this.getPathWithoutLocale(t), s = this.ctx.globalLocaleRoutes, r = e === "/" ? "/" : z(e);
|
|
301
302
|
if (s && (s[e] === !1 || s[r] === !1) || h !== null) return null;
|
|
302
303
|
const o = this.resolvePathForLocale(e, a), P = this.shouldHavePrefix(a);
|
|
303
304
|
let i;
|
|
304
305
|
P ? i = b(`/${a}${o.startsWith("/") ? o : `/${o}`}`) : i = o.startsWith("/") ? o : `/${o}`, i !== "/" && i.endsWith("/") && (i = i.slice(0, -1));
|
|
305
|
-
const
|
|
306
|
-
return U(
|
|
306
|
+
const f = g(t);
|
|
307
|
+
return U(f, i) ? null : i;
|
|
307
308
|
}
|
|
308
309
|
}
|
|
309
310
|
export {
|