@i18n-micro/path-strategy 1.1.1 → 1.1.2
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/dist/base-strategy-BuHeTv1K.cjs +2 -0
- package/dist/base-strategy-BuHeTv1K.cjs.map +1 -0
- package/dist/{base-strategy-PVpkf05w.js → base-strategy-Cf39XK8k.js} +78 -56
- package/dist/base-strategy-Cf39XK8k.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- 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.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.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.mjs +28 -25
- 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.mjs +1 -1
- package/dist/prefix-strategy.mjs.map +1 -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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefix-except-default-strategy.mjs","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":";AAMO,MAAMA,UAAwCC,EAAiB;AAAA;AAAA;AAAA;AAAA;AAAA,EAK1D,iBAAiBC,GAAyB;AAClD,QAAI,KAAK,IAAI,0BAA2B,QAAO;AAC/C,QAAIA,MAAW,KAAK,IAAI,cAAe,QAAO;AAE9C,UAAMC,IAAY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AAOA,EAAO;AAGlB,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,qBAAqBG,GAAcK,GAAoBC,GAA0B;AAC/E,WAAIA,MAAa,KAAK,IAAI,gBACjB,IAAID,CAAU,GAAGL,CAAI,KAEvBA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,kBAAkBuD,GAAqB4B,GAAwC;AAC7E,UAAM,EAAE,mBAAAnE,GAAmB,gBAAAsC,EAAA,IAAmB,KAAK,qBAAqBC,CAAW,GAG7EG,IAAK,KAAK,IAAI,oBACdC,IAAU3C,MAAsB,MAAM,MAAM4C,EAAoB5C,CAAiB;AAMvF,QALI0C,MAAOA,EAAG1C,CAAiB,MAAM,MAAS0C,EAAGC,CAAO,MAAM,OAK1DL,MAAmB,KAAM,QAAO;AAGpC,UAAM8B,IAAa,KAAK,qBAAqBpE,GAAmBmE,CAAe,GACzEE,IAAc,KAAK,iBAAiBF,CAAe;AAGzD,QAAIlE;AACJ,IAAIoE,IACFpE,IAAaoC,EAAmB,IAAI8B,CAAe,GAAGC,EAAW,WAAW,GAAG,IAAIA,IAAa,IAAIA,CAAU,EAAE,EAAE,IAGlHnE,IAAamE,EAAW,WAAW,GAAG,IAAIA,IAAa,IAAIA,CAAU,IAInEnE,MAAe,OAAOA,EAAW,SAAS,GAAG,MAC/CA,IAAaA,EAAW,MAAM,GAAG,EAAE;AAIrC,UAAMqE,IAAetB,EAAaT,CAAW;AAC7C,WAAIU,EAAWqB,GAAcrE,CAAU,IAAU,OAE1CA;AAAA,EACT;AACF;"}
|
|
1
|
+
{"version":3,"file":"prefix-except-default-strategy.mjs","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 * 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(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":";AAiBO,MAAMA,UAAwCC,EAAiB;AAAA;AAAA;AAAA;AAAA;AAAA,EAK1D,iBAAiBC,GAAyB;AAClD,QAAI,KAAK,IAAI,0BAA2B,QAAO;AAC/C,QAAIA,MAAW,KAAK,IAAI,cAAe,QAAO;AAE9C,UAAMC,IAAY,KAAK,IAAI,QAAQ,KAAK,CAACC,MAAMA,EAAE,SAASF,CAAM;AAChE,WA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,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,qBAAqBG,GAAcK,GAAoBC,GAA0B;AAC/E,WAAIA,MAAa,KAAK,IAAI,gBACjB,IAAID,CAAU,GAAGL,CAAI,KAEvBA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,kBAAkBuD,GAAqB4B,GAAwC;AAC7E,UAAM,EAAE,mBAAAnE,GAAmB,gBAAAsC,EAAA,IAAmB,KAAK,qBAAqBC,CAAW,GAG7EG,IAAK,KAAK,IAAI,oBACdC,IAAU3C,MAAsB,MAAM,MAAM4C,EAAoB5C,CAAiB;AAMvF,QALI0C,MAAOA,EAAG1C,CAAiB,MAAM,MAAS0C,EAAGC,CAAO,MAAM,OAK1DL,MAAmB,KAAM,QAAO;AAGpC,UAAM8B,IAAa,KAAK,qBAAqBpE,GAAmBmE,CAAe,GACzEE,IAAc,KAAK,iBAAiBF,CAAe;AAGzD,QAAIlE;AACJ,IAAIoE,IACFpE,IAAaoC,EAAmB,IAAI8B,CAAe,GAAGC,EAAW,WAAW,GAAG,IAAIA,IAAa,IAAIA,CAAU,EAAE,EAAE,IAElHnE,IAAamE,EAAW,WAAW,GAAG,IAAIA,IAAa,IAAIA,CAAU,IAInEnE,MAAe,OAAOA,EAAW,SAAS,GAAG,MAC/CA,IAAaA,EAAW,MAAM,GAAG,EAAE;AAIrC,UAAMqE,IAAetB,EAAaT,CAAW;AAC7C,WAAIU,EAAWqB,GAAcrE,CAAU,IAAU,OAE1CA;AAAA,EACT;AACF;"}
|
package/dist/prefix-strategy.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./base-strategy-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./base-strategy-BuHeTv1K.cjs");class u extends l.BasePathStrategy{buildLocalizedPath(a,e,t){return l.joinUrl(e,l.normalizePath(a))}buildLocalizedRouteName(a,e){return this.buildLocalizedName(a,e)}getCanonicalPath(a,e){const t=this.getCustomPathSegment(a,e);if(!t)return null;const o=t.startsWith("/")?t:`/${t}`;return l.cleanDoubleSlashes(`/${e}${o}`)}resolveLocaleFromPath(a){const{localeFromPath:e}=this.getPathWithoutLocale(a);return e}getRedirect(a,e){const{pathWithoutLocale:t,localeFromPath:o}=this.getPathWithoutLocale(a),s=this.ctx.globalLocaleRoutes,n=t==="/"?"/":l.withoutLeadingSlash(t),i=s&&(s[t]===!1||s[n]===!1);if(i&&o!==null)return l.normalizePathForCompare(t);if(i&&o===null)return null;const r=this.buildPathWithPrefix(t,e),h=l.getCleanPath(a);return o===e&&l.isSamePath(h,r)?null:r}buildPathWithPrefix(a,e){const t=this.resolvePathForLocale(a,e);if(t==="/"||t==="")return`/${e}`;const o=`/${e}`,s=t.startsWith("/")?t:`/${t}`;return l.cleanDoubleSlashes(o+s)}formatPathForResolve(a,e,t){return`/${e}${a}`}getClientRedirect(a,e){const{pathWithoutLocale:t,localeFromPath:o}=this.getPathWithoutLocale(a),s=this.ctx.globalLocaleRoutes,n=t==="/"?"/":l.withoutLeadingSlash(t);if(s&&(s[t]===!1||s[n]===!1)||o!==null)return null;const i=this.resolvePathForLocale(t,e);let r=l.cleanDoubleSlashes(`/${e}${i.startsWith("/")?i:`/${i}`}`);r!=="/"&&r.endsWith("/")&&(r=r.slice(0,-1));const h=l.getCleanPath(a);return l.isSamePath(h,r)?null:r}}exports.PrefixPathStrategy=u;exports.Strategy=u;
|
|
2
2
|
//# sourceMappingURL=prefix-strategy.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefix-strategy.cjs","sources":["../src/strategies/prefix.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"prefix-strategy.cjs","sources":["../src/strategies/prefix.ts"],"sourcesContent":["import { cleanDoubleSlashes, isSamePath, withoutLeadingSlash } from 'ufo'\nimport type { ResolvedRouteLike } from '../core/types'\nimport { getCleanPath, joinUrl, normalizePath, normalizePathForCompare } from '../utils/path'\nimport { BasePathStrategy } from './base-strategy'\n\nexport class PrefixPathStrategy 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 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 return cleanDoubleSlashes(`/${targetLocale}${normalized}`)\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 const gr = this.ctx.globalLocaleRoutes\n const pathKey = pathWithoutLocale === '/' ? '/' : withoutLeadingSlash(pathWithoutLocale)\n const isUnlocalized = gr && (gr[pathWithoutLocale] === false || gr[pathKey] === false)\n if (isUnlocalized && localeFromPath !== null) {\n return normalizePathForCompare(pathWithoutLocale)\n }\n if (isUnlocalized && localeFromPath === null) {\n return null\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 const prefix = `/${locale}`\n const withSlash = resolved.startsWith('/') ? resolved : `/${resolved}`\n return cleanDoubleSlashes(prefix + withSlash)\n }\n\n /**\n * Formats path for router.resolve.\n * prefix: always add locale prefix.\n */\n formatPathForResolve(path: string, fromLocale: string, _toLocale: string): string {\n return `/${fromLocale}${path}`\n }\n\n /**\n * prefix strategy: redirect only if URL has no locale prefix.\n * Does NOT redirect if user explicitly navigates to a locale path.\n * Uses custom paths from globalLocaleRoutes when available.\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 (uses globalLocaleRoutes)\n const customPath = this.resolvePathForLocale(pathWithoutLocale, preferredLocale)\n let targetPath = cleanDoubleSlashes(`/${preferredLocale}${customPath.startsWith('/') ? customPath : `/${customPath}`}`)\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: only this strategy is bundled when importing from #i18n-strategy. */\nexport { PrefixPathStrategy as Strategy }\n"],"names":["PrefixPathStrategy","BasePathStrategy","path","locale","_isCustom","joinUrl","normalizePath","baseName","route","targetLocale","segment","normalized","cleanDoubleSlashes","localeFromPath","currentPath","detectedLocale","pathWithoutLocale","gr","pathKey","withoutLeadingSlash","isUnlocalized","normalizePathForCompare","expectedPath","currentPathOnly","getCleanPath","isSamePath","resolved","prefix","withSlash","fromLocale","_toLocale","preferredLocale","customPath","targetPath","currentClean"],"mappings":"gIAKO,MAAMA,UAA2BC,EAAAA,gBAAiB,CAC7C,mBAAmBC,EAAcC,EAAgBC,EAA4B,CACrF,OAAOC,UAAQF,EAAQG,EAAAA,cAAc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EAAAA,mBAAmBe,EAASC,CAAS,CAC9C,CAMA,qBAAqB1B,EAAc2B,EAAoBC,EAA2B,CAChF,MAAO,IAAID,CAAU,GAAG3B,CAAI,EAC9B,CAOA,kBAAkBY,EAAqBiB,EAAwC,CAC7E,KAAM,CAAE,kBAAAf,EAAmB,eAAAH,CAAA,EAAmB,KAAK,qBAAqBC,CAAW,EAG7EG,EAAK,KAAK,IAAI,mBACdC,EAAUF,IAAsB,IAAM,IAAMG,EAAAA,oBAAoBH,CAAiB,EAMvF,GALIC,IAAOA,EAAGD,CAAiB,IAAM,IAASC,EAAGC,CAAO,IAAM,KAK1DL,IAAmB,KAAM,OAAO,KAGpC,MAAMmB,EAAa,KAAK,qBAAqBhB,EAAmBe,CAAe,EAC/E,IAAIE,EAAarB,EAAAA,mBAAmB,IAAImB,CAAe,GAAGC,EAAW,WAAW,GAAG,EAAIA,EAAa,IAAIA,CAAU,EAAE,EAAE,EAGlHC,IAAe,KAAOA,EAAW,SAAS,GAAG,IAC/CA,EAAaA,EAAW,MAAM,EAAG,EAAE,GAIrC,MAAMC,EAAeV,EAAAA,aAAaV,CAAW,EAC7C,OAAIW,aAAWS,EAAcD,CAAU,EAAU,KAE1CA,CACT,CACF"}
|
package/dist/prefix-strategy.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as g, j as m, n as f, c as h, w as u, a as d, g as c, i as P } from "./base-strategy-
|
|
1
|
+
import { B as g, j as m, n as f, c as h, w as u, a as d, g as c, i as P } from "./base-strategy-Cf39XK8k.js";
|
|
2
2
|
class $ extends g {
|
|
3
3
|
buildLocalizedPath(a, e, t) {
|
|
4
4
|
return m(e, f(a));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefix-strategy.mjs","sources":["../src/strategies/prefix.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"prefix-strategy.mjs","sources":["../src/strategies/prefix.ts"],"sourcesContent":["import { cleanDoubleSlashes, isSamePath, withoutLeadingSlash } from 'ufo'\nimport type { ResolvedRouteLike } from '../core/types'\nimport { getCleanPath, joinUrl, normalizePath, normalizePathForCompare } from '../utils/path'\nimport { BasePathStrategy } from './base-strategy'\n\nexport class PrefixPathStrategy 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 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 return cleanDoubleSlashes(`/${targetLocale}${normalized}`)\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 const gr = this.ctx.globalLocaleRoutes\n const pathKey = pathWithoutLocale === '/' ? '/' : withoutLeadingSlash(pathWithoutLocale)\n const isUnlocalized = gr && (gr[pathWithoutLocale] === false || gr[pathKey] === false)\n if (isUnlocalized && localeFromPath !== null) {\n return normalizePathForCompare(pathWithoutLocale)\n }\n if (isUnlocalized && localeFromPath === null) {\n return null\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 const prefix = `/${locale}`\n const withSlash = resolved.startsWith('/') ? resolved : `/${resolved}`\n return cleanDoubleSlashes(prefix + withSlash)\n }\n\n /**\n * Formats path for router.resolve.\n * prefix: always add locale prefix.\n */\n formatPathForResolve(path: string, fromLocale: string, _toLocale: string): string {\n return `/${fromLocale}${path}`\n }\n\n /**\n * prefix strategy: redirect only if URL has no locale prefix.\n * Does NOT redirect if user explicitly navigates to a locale path.\n * Uses custom paths from globalLocaleRoutes when available.\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 (uses globalLocaleRoutes)\n const customPath = this.resolvePathForLocale(pathWithoutLocale, preferredLocale)\n let targetPath = cleanDoubleSlashes(`/${preferredLocale}${customPath.startsWith('/') ? customPath : `/${customPath}`}`)\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: only this strategy is bundled when importing from #i18n-strategy. */\nexport { PrefixPathStrategy as Strategy }\n"],"names":["PrefixPathStrategy","BasePathStrategy","path","locale","_isCustom","joinUrl","normalizePath","baseName","route","targetLocale","segment","normalized","cleanDoubleSlashes","localeFromPath","currentPath","detectedLocale","pathWithoutLocale","gr","pathKey","withoutLeadingSlash","isUnlocalized","normalizePathForCompare","expectedPath","currentPathOnly","getCleanPath","isSamePath","resolved","prefix","withSlash","fromLocale","_toLocale","preferredLocale","customPath","targetPath","currentClean"],"mappings":";AAKO,MAAMA,UAA2BC,EAAiB;AAAA,EAC7C,mBAAmBC,GAAcC,GAAgBC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AYF,EAAS,WAAW,GAAG,IAAIA,IAAW,IAAIA,CAAQ;AACpE,WAAOd,EAAmBe,IAASC,CAAS;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,qBAAqB1B,GAAc2B,GAAoBC,GAA2B;AAChF,WAAO,IAAID,CAAU,GAAG3B,CAAI;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,kBAAkBY,GAAqBiB,GAAwC;AAC7E,UAAM,EAAE,mBAAAf,GAAmB,gBAAAH,EAAA,IAAmB,KAAK,qBAAqBC,CAAW,GAG7EG,IAAK,KAAK,IAAI,oBACdC,IAAUF,MAAsB,MAAM,MAAMG,EAAoBH,CAAiB;AAMvF,QALIC,MAAOA,EAAGD,CAAiB,MAAM,MAASC,EAAGC,CAAO,MAAM,OAK1DL,MAAmB,KAAM,QAAO;AAGpC,UAAMmB,IAAa,KAAK,qBAAqBhB,GAAmBe,CAAe;AAC/E,QAAIE,IAAarB,EAAmB,IAAImB,CAAe,GAAGC,EAAW,WAAW,GAAG,IAAIA,IAAa,IAAIA,CAAU,EAAE,EAAE;AAGtH,IAAIC,MAAe,OAAOA,EAAW,SAAS,GAAG,MAC/CA,IAAaA,EAAW,MAAM,GAAG,EAAE;AAIrC,UAAMC,IAAeV,EAAaV,CAAW;AAC7C,WAAIW,EAAWS,GAAcD,CAAU,IAAU,OAE1CA;AAAA,EACT;AACF;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/path-strategy",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Shared strategy-based path and route name builder for Nuxt I18n Micro frontend routing.",
|
|
5
5
|
"repository": "s00d/nuxt-i18n-micro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
],
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"ufo": "^1.5.4",
|
|
76
|
-
"@i18n-micro/types": "1.1.
|
|
76
|
+
"@i18n-micro/types": "1.1.1"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"vite": "^7.3.1",
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const ct=/#/g,ht=/&/g,ut=/\//g,ft=/=/g,q=/\+/g,Y=/%5e/gi,dt=/%60/gi,pt=/%7b/gi,mt=/%7c/gi,gt=/%7d/gi,Pt=/%20/gi;function Z(o){return encodeURI(""+o).replace(mt,"|")}function yt(o){return Z(o).replace(pt,"{").replace(gt,"}").replace(Y,"^")}function k(o){return Z(typeof o=="string"?o:JSON.stringify(o)).replace(q,"%2B").replace(Pt,"+").replace(ct,"%23").replace(ht,"%26").replace(dt,"`").replace(Y,"^").replace(ut,"%2F")}function E(o){return k(o).replace(ft,"%3D")}function A(o=""){try{return decodeURIComponent(""+o)}catch{return""+o}}function Rt(o){return A(o.replace(q," "))}function Lt(o){return A(o.replace(q," "))}function xt(o=""){const t=Object.create(null);o[0]==="?"&&(o=o.slice(1));for(const e of o.split("&")){const a=e.match(/([^=]+)=?(.*)/)||[];if(a.length<2)continue;const s=Rt(a[1]);if(s==="__proto__"||s==="constructor")continue;const r=Lt(a[2]||"");t[s]===void 0?t[s]=r:Array.isArray(t[s])?t[s].push(r):t[s]=[t[s],r]}return t}function bt(o,t){return(typeof t=="number"||typeof t=="boolean")&&(t=String(t)),t?Array.isArray(t)?t.map(e=>`${E(o)}=${k(e)}`).join("&"):`${E(o)}=${k(t)}`:E(o)}function Nt(o){return Object.keys(o).filter(t=>o[t]!==void 0).map(t=>bt(t,o[t])).filter(Boolean).join("&")}const zt=/^[\s\w\0+.-]{2,}:([/\\]{1,2})/,vt=/^[\s\w\0+.-]{2,}:([/\\]{2})?/,St=/^([/\\]\s*){2,}[^/\\]/,Bt=/^\.?\//;function v(o,t={}){return typeof t=="boolean"&&(t={acceptRelative:t}),t.strict?zt.test(o):vt.test(o)||(t.acceptRelative?St.test(o):!1)}function Wt(o="",t){return o.endsWith("/")}function S(o="",t){return(Wt(o)?o.slice(0,-1):o)||"/"}function Ft(o="",t){return o.endsWith("/")?o:o+"/"}function U(o=""){return o.startsWith("/")}function w(o=""){return(U(o)?o.slice(1):o)||"/"}function O(o=""){return U(o)?o:"/"+o}function Q(o=""){return o.split("://").map(t=>t.replace(/\/{2,}/g,"/")).join("://")}function At(o,t){const e=I(o),a={...xt(e.search),...t};return e.search=Nt(a),et(e)}function _t(o){return!o||o==="/"}function Ut(o){return o&&o!=="/"}function T(o,...t){let e=o||"";for(const a of t.filter(s=>Ut(s)))if(e){const s=a.replace(Bt,"");e=Ft(e)+s}else e=a;return e}function Ct(o,t){return A(S(o))===A(S(t))}function Et(o,t){if(!t||t==="#")return o;const e=I(o);return e.hash=t===""?"":"#"+yt(t),et(e)}const tt=Symbol.for("ufo:protocolRelative");function I(o="",t){const e=o.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);if(e){const[,d,g=""]=e;return{protocol:d.toLowerCase(),pathname:g,href:d+g,auth:"",host:"",search:"",hash:""}}if(!v(o,{acceptRelative:!0}))return _(o);const[,a="",s,r=""]=o.replace(/\\/g,"/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/)||[];let[,n="",l=""]=r.match(/([^#/?]*)(.*)?/)||[];a==="file:"&&(l=l.replace(/\/(?=[A-Za-z]:)/,""));const{pathname:i,search:h,hash:u}=_(l);return{protocol:a.toLowerCase(),auth:s?s.slice(0,Math.max(0,s.length-1)):"",host:n,pathname:i,search:h,hash:u,[tt]:!a}}function _(o=""){const[t="",e="",a=""]=(o.match(/([^#?]*)(\?[^#]*)?(#.*)?/)||[]).splice(1);return{pathname:t,search:e,hash:a}}function et(o){const t=o.pathname||"",e=o.search?(o.search.startsWith("?")?"":"?")+o.search:"",a=o.hash||"",s=o.auth?o.auth+"@":"",r=o.host||"";return(o.protocol||o[tt]?(o.protocol||"")+"//":"")+s+r+t+e+a}const kt=/\/([^/]+)$/;function wt(o="",t){const{pathname:e}=I(o),a=e.match(kt);return a?a[1]:void 0}function H(o){return(_(o.startsWith("/")?o:`/${o}`).pathname||"").split("/").filter(Boolean)}const y=o=>_t(o??"")?"/":O(S(Q(o)))||"/";function $t(o){const t=Q(o||"/");return S(t)||"/"}function P(...o){const t=o.filter(r=>typeof r=="string"&&r!=="");if(t.length===0)return"/";const[e,...a]=t,s=T(e,...a)||"/";return v(s)?s:O(s)}function K(o){return o&&_(o).pathname||""}function $(o,t,e){let a=At(o,t??{});if(e&&e!=="#"){const s=e.startsWith("#")?e.slice(1):e;a=Et(a,s)}return a}function x(o){if(!o)return"";let t="";for(let e=0;e<o.length;e++)t+=o[e]==="-"?"/":o[e];return t}function G(o){if(!o)return"";const t=o.indexOf("-");return t===-1?o:T(o.slice(0,t),o.slice(t+1))}function M(o){if(!o)return"";const t=o.lastIndexOf("-");return t===-1?o:T(o.slice(0,t),o.slice(t+1))}function jt(o){const t=H(o);return t.length>1?t.slice(0,-1).join("-"):""}function qt(o){return wt(o||"/")??""}function V(o,t){const e=o.name?.toString();if(!e)return null;const a=t.localizedRouteNamePrefix||"localized-",s=e.startsWith(a)?e.slice(a.length):e,r=[...t.locales].sort((n,l)=>l.code.length-n.code.length);for(const n of r){const l=`-${n.code}`;if(!s.endsWith(l))continue;const i=s.length-n.code.length-1;if(i>=0&&s[i]==="-")return s.slice(0,-l.length)}return s}function at(o,t,e="localized-"){return`${e}${o}-${t}`}function j(o,t){if(o==null)return!1;const e=String(o).trim();if(e===""||e==="index")return!0;const a=t?.localizedRouteNamePrefix??"localized-",s=t?.localeCodes??[],r=`${a}index-`;if(!e.startsWith(r))return!1;const n=e.slice(r.length);return s.length===0?n.length>=2:s.includes(n)}function X(o,t){const e=K(o),a=y(e);if(a==="/")return{pathWithoutLocale:"/",localeFromPath:null};if(!U(a))return{pathWithoutLocale:a,localeFromPath:null};const s=a.indexOf("/",1),r=s===-1?a.slice(1):a.slice(1,s);if(r&&t.includes(r)){const n=1+r.length,l=a.slice(n);return{pathWithoutLocale:y(l||"/"),localeFromPath:r}}return{pathWithoutLocale:a,localeFromPath:null}}function st(o,t){const e=K(o);if(e==="/"||e===""||!U(e))return null;const a=e.indexOf("/",1),s=a===-1?e.slice(1):e.slice(1,a);return s&&t.includes(s)?s:null}function Ot(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}class ot{constructor(t){this.ctx=t}resolvePathWithParams(t,e={}){let a=t;for(const s in e){const r=e[s];if(r==null||r==="")continue;const n=Array.isArray(r)?r.join("/"):String(r),l=Ot(s),i=new RegExp(`:${l}\\(\\)|:${l}(?![\\w])|\\[\\.\\.\\.${l}\\]`,"g");a=a.replace(i,n)}return a}analyzeRoute(t){const e=this.ctx.locales.map(r=>r.code),{pathWithoutLocale:a}=X(t.path||"/",e);let s=null;return t.name&&(s=V(t,{locales:this.ctx.locales,localizedRouteNamePrefix:this.ctx.localizedRouteNamePrefix||"localized-"})),{pathWithoutLocale:a,baseRouteName:s}}getPathWithoutLocaleAndBaseName(t){return this.analyzeRoute(t)}getLookupKeys(t,e){const a=[];a.push(t);const s=w(t);if(s!==t&&a.push(s),(t==="/"||s==="")&&a.push(""),e){a.push(`/${e}`),a.push(e);const r=x(e);r&&r!==e&&a.push(r);const n=G(e);n&&a.push(n);const l=M(e);l&&a.push(l)}return a}resolveCustomPath(t,e){const a=this.ctx.globalLocaleRoutes;if(!a||Object.keys(a).length===0)return null;const{pathWithoutLocale:s,baseRouteName:r}=this.analyzeRoute(t),n=this.getLookupKeys(s,r);for(const l of n){const i=a[l];if(i&&typeof i=="object"&&!Array.isArray(i)){const h=i[e];if(typeof h=="string")return this.resolvePathWithParams(h,t.params??{})}}return null}getPathForUnlocalizedRoute(t){const e=this.ctx.globalLocaleRoutes;if(!e)return null;const{pathWithoutLocale:a,baseRouteName:s}=this.analyzeRoute(t),r=this.getLookupKeys(a,s);for(const n of r)if(e[n]===!1){if(s&&(n===s||n===`/${s}`)){const l=x(s);return l?P("/",l):`/${s}`}return a}return null}getPathForUnlocalizedRouteByName(t){const e=this.ctx.globalLocaleRoutes;if(!e)return null;const a=[t,`/${t}`,w(t)];for(const s of a)if(e[s]===!1){const r=x(s.startsWith("/")?s.slice(1):s);return r?P("/",r):s.startsWith("/")?s:`/${s}`}return null}getAllowedLocalesForRoute(t){const e=this.ctx.routeLocales;if(!e||Object.keys(e).length===0)return this.ctx.locales.map(n=>n.code);const{pathWithoutLocale:a,baseRouteName:s}=this.analyzeRoute(t);let r=this.getLookupKeys(a,s);s&&this.ctx.routesLocaleLinks?.[s]&&(r=[this.ctx.routesLocaleLinks[s],...r]);for(const n of r){const l=e[n];if(Array.isArray(l)&&l.length>0)return l.filter(i=>this.ctx.locales.some(h=>h.code===i))}return this.ctx.locales.map(n=>n.code)}getParentPathForNested(t,e){if(t.length<=1)return"/";const a=t.length>1?t.slice(0,-1).join("-"):"",s=this.ctx.globalLocaleRoutes;if(a&&s?.[a]&&typeof s[a]=="object"){const r=s[a];if(r[e])return y(r[e])}return P("/",...t.slice(0,-1))}}class Qt{constructor(t){this.ctx=t,this.resolver=new ot(t)}setRouter(t){this.ctx.router=t}getDefaultLocale(){return this.ctx.defaultLocale}getLocales(){return this.ctx.locales}getStrategy(){return this.ctx.strategy}getLocalizedRouteNamePrefix(){return this.ctx.localizedRouteNamePrefix||"localized-"}getGlobalLocaleRoutes(){return this.ctx.globalLocaleRoutes}getRouteLocales(){return this.ctx.routeLocales}getRoutesLocaleLinks(){return this.ctx.routesLocaleLinks}getNoPrefixRedirect(){return this.ctx.noPrefixRedirect}getRouteBaseName(t,e){const a=e?[{code:e}]:this.ctx.locales;return V(t,{locales:a,localizedRouteNamePrefix:this.getLocalizedRouteNamePrefix()})}getBaseRouteName(t,e){return this.getRouteBaseName(t,e)}resolvePathForLocale(t,e){const a={path:t,name:null,fullPath:t,params:{}},s=this.resolver.resolveCustomPath(a,e);return y(s||t)}buildLocalizedName(t,e){return at(t,e,this.getLocalizedRouteNamePrefix())}getLocaleObject(t){return this.ctx.locales.find(e=>e.code===t)}applyBaseUrl(t,e){if(typeof e=="string"){if(v(e))return e}else if(e.path&&v(e.path))return e;const a=this.getLocaleObject(t);if(!a?.baseUrl)return e;const s=S(a.baseUrl);if(typeof e=="string"){const l=y(e.startsWith("/")?e:`/${e}`);return P(s,l)}const r=y(e.path||""),n=P(s,r);return v(n)?n:{...e,path:n,fullPath:n}}preserveQueryAndHash(t,e){if(!e||!e.query&&!e.hash)return t;const a=typeof t=="string"?{path:t}:{...t};e.query&&(a.query={...e.query,...a.query}),!a.hash&&e.hash&&(a.hash=e.hash);const s=a.path??"";return a.fullPath=$(s,a.query,a.hash),a}resolvePathWithParams(t,e={}){return this.resolver.resolvePathWithParams(t,e)}getPathWithoutLocaleAndBaseName(t){return this.resolver.getPathWithoutLocaleAndBaseName(t)}getCustomPathSegment(t,e){return this.resolver.resolveCustomPath(t,e)}getAllowedLocalesForRoute(t){return this.resolver.getAllowedLocalesForRoute(t)}getCanonicalPath(t,e){return null}getPathForUnlocalizedRouteByName(t){return this.resolver.getPathForUnlocalizedRouteByName(t)}tryResolveByLocalizedName(t,e,a){const s=this.getLocalizedRouteNamePrefix(),r=`${s}${t}-${e}`,n=`${s}${t}`;let l;if(this.ctx.router.hasRoute(r))l=r;else if(this.ctx.router.hasRoute(n))l=n;else return this.debugLog("tryResolveByLocalizedName",{routeName:t,targetLocale:e,tried:[r,n],found:!1}),null;this.debugLog("tryResolveByLocalizedName",{routeName:t,targetLocale:e,localizedName:l,found:!0});const i={...a?.params};l===n&&(i.locale=e);let h;try{h=this.ctx.router.resolve({name:l,params:i,query:a?.query,hash:a?.hash})}catch{return this.debugLog("tryResolveByLocalizedName resolve error",{localizedName:l,params:i}),null}return this.debugLog("tryResolveByLocalizedName resolved",{localizedName:l,path:h?.path,fullPath:h?.fullPath}),h?.path?{name:l,path:h.path,fullPath:h.fullPath,params:h.params,query:h.query??a?.query,hash:h.hash??a?.hash}:null}tryResolveByLocalizedNameWithParams(t,e,a,s){const r=this.getLocalizedRouteNamePrefix(),n=`${r}${t}-${e}`,l=`${r}${t}`;let i;if(this.ctx.router.hasRoute(n))i=n;else if(this.ctx.router.hasRoute(l))i=l;else return this.debugLog("tryResolveByLocalizedNameWithParams",{routeName:t,targetLocale:e,params:a,tried:[n,l],found:!1}),null;this.debugLog("tryResolveByLocalizedNameWithParams",{routeName:t,targetLocale:e,params:a,localizedName:i,found:!0});const h={...a};i===l&&(h.locale=e);let u;try{u=this.ctx.router.resolve({name:i,params:h,query:s?.query,hash:s?.hash})}catch{return this.debugLog("tryResolveByLocalizedNameWithParams resolve error",{localizedName:i,resolveParams:h}),null}return this.debugLog("tryResolveByLocalizedNameWithParams resolved",{path:u?.path,fullPath:u?.fullPath}),!u?.path||u.path==="/"?null:{name:i,path:u.path,fullPath:u.fullPath,params:u.params,query:u.query??s?.query,hash:u.hash??s?.hash}}getPathForUnlocalizedRoute(t){return this.resolver.getPathForUnlocalizedRoute(t)}buildPathFromBaseNameAndParams(t,e,a){const s=Object.keys(e).filter(u=>e[u]!==void 0&&e[u]!==null&&e[u]!=="");if(s.length===0)return null;let r;const n=s[0];if(s.length===1&&n!==void 0&&t.endsWith("-"+n))r=P("/",t.slice(0,t.length-n.length-1)+"-:"+n);else{const u=x(t),d=u?u.split("/").filter(Boolean):[t],g=Math.min(s.length,d.length),R=d.slice(0,d.length-g).concat(s.slice(0,g).map(B=>`:${B}`));r=P("/",...R)}const l=this.resolvePathWithParams(r,e),i=this.buildLocalizedPath(l,a,!1),h=this.applyBaseUrl(a,i);return typeof h=="string"?h:h.path??i}getPathWithoutLocale(t){return X(t,this.ctx.locales.map(e=>e.code))}getLocaleFromPath(t){return st(t,this.ctx.locales.map(e=>e.code))}shouldReturn404(t){const{pathWithoutLocale:e,localeFromPath:a}=this.getPathWithoutLocale(t);if(a===null)return null;const s=e==="/"?"/":e.replace(/^\//,""),r=this.ctx.globalLocaleRoutes;if(r&&(r[e]===!1||r[s]===!1))return"Unlocalized route cannot have locale prefix";const n=this.ctx.routeLocales;if(n&&Object.keys(n).length>0){const l=n[e]??n[s];if(Array.isArray(l)&&l.length>0){const i=this.ctx.locales.map(u=>u.code),h=l.filter(u=>i.includes(u));if(h.length>0&&!h.includes(a))return"Locale not allowed for this route"}}return null}getSeoAttributes(t){const e=this.resolveLocaleFromPath(t.path)??this.ctx.defaultLocale,a=this.getCanonicalPath(t,e)??t.path,s=this.buildFullUrl(e,a),r=this.getAllowedLocalesForRoute(t),l=this.ctx.locales.filter(i=>r.includes(i.code)).map(i=>{const h=this.localeRoute(i.code,t,t),d=(h.path??h.fullPath??"")||"/";return{rel:"alternate",hreflang:i.code,href:this.buildFullUrl(i.code,d)}});return{canonical:s,hreflangs:l}}buildFullUrl(t,e){const a=this.applyBaseUrl(t,e);return typeof a=="string"?a:a.path??e}getSwitchLocaleFallbackWhenNoRoute(t,e){return{...t,name:e}}switchLocaleRoute(t,e,a,s){const r=this.getBaseRouteName(a,t);if(!r)return a;const n=this.buildLocalizedRouteName(r,e),l=`${this.getLocalizedRouteNamePrefix()}${r}`;let i,h=!1;if(this.ctx.router.hasRoute(n))i=n;else if(this.ctx.router.hasRoute(l))i=l,h=!0;else if(this.ctx.router.hasRoute(r))i=r;else return this.getSwitchLocaleFallbackWhenNoRoute(a,n);const u=s.i18nRouteParams?.[e]||{},d={...a.params||{},...u};h?d.locale=e:delete d.locale;const g={name:i,params:d,query:a.query,hash:a.hash};return this.applyBaseUrl(e,g)}localeRoute(t,e,a){const s=this.normalizeRouteInput(e,a),r=this.resolveLocaleRoute(t,s,a);this.debugLog("localeRoute raw",{rawPath:typeof r=="string"?r:r.path,rawFullPath:typeof r=="string"?r:r.fullPath});const n=this.ensureRouteLike(r,s.kind==="route"?s.sourceRoute:void 0);return this.debugLog("localeRoute after ensureRouteLike",{path:n.path,fullPath:n.fullPath}),n}ensureRouteLike(t,e){if(typeof t=="string"){const r=t,n=e?.query||e?.hash?$(r,e?.query,e?.hash):r;return{path:r,fullPath:n,...e?.query&&{query:e.query},...e?.hash&&{hash:e.hash}}}let a=t.fullPath??t.path??"",s=t.path??a.split("?")[0]?.split("#")[0]??a;if(!s&&!a){const r=t.name?.toString()??e?.name?.toString()??"";j(r,{localizedRouteNamePrefix:this.getLocalizedRouteNamePrefix(),localeCodes:this.ctx.locales.map(n=>n.code)})&&(s="/",a="/")}return{...t,path:s,fullPath:a}}normalizeRouteInput(t,e){if(typeof t=="string")return{kind:"path",path:t};const a=t,s=a.name?.toString()??null;let r;try{r=this.ctx.router.resolve(t),this.debugLog("normalizeRouteInput router.resolve ok",{inputName:s,resolvedPath:r.path,resolvedName:r.name})}catch{r={name:s,path:a.path??"/",fullPath:a.fullPath??a.path??"/",params:a.params??{},query:a.query??{},hash:a.hash??""},this.debugLog("normalizeRouteInput router.resolve catch fallback",{inputName:s,resolvedPath:r.path})}return{kind:"route",inputName:s,sourceRoute:a,resolved:r}}debugLog(...t){}resolveLocaleRoute(t,e,a){if(e.kind==="path"){const c=this.resolvePathForLocale(e.path,t),f=this.buildLocalizedPath(c,t,!1),p=this.applyBaseUrl(t,f);return this.debugLog("branch=path",{targetLocale:t,path:e.path,finalPath:f,out:typeof p=="string"?p:p.path}),p}const{inputName:s,sourceRoute:r,resolved:n}=e,l=r.params&&Object.keys(r.params??{}).length>0,i=this.getRouteBaseName(n)??s??n.name?.toString()??null,h=n.name?.toString();if(this.debugLog("input",{targetLocale:t,inputName:s,resolvedPath:n.path,resolvedName:n.name,params:r.params,hasParams:l,baseName:i}),s){const c=this.getPathForUnlocalizedRouteByName(s);if(c!==null)return this.debugLog("branch=unlocalizedByName",{inputName:s,unlocalizedByName:c}),this.preserveQueryAndHash(c,r)}if(s&&l){const c=this.tryResolveByLocalizedNameWithParams(s,t,r.params??{},r);if(c!==null)return this.debugLog("branch=routeWithParams",{inputName:s,path:c.path,fullPath:c.fullPath}),this.preserveQueryAndHash(this.applyBaseUrl(t,c),r)}if(s&&!l){let c=this.tryResolveByLocalizedName(s,t,r);const f=this.getLocalizedRouteNamePrefix();if(c===null&&i!=null&&i!==s&&s.startsWith(f)&&(c=this.tryResolveByLocalizedName(i,t,r)),c!==null)return this.debugLog("branch=routeByLocalizedName",{inputName:s,path:c.path,fullPath:c.fullPath}),this.preserveQueryAndHash(this.applyBaseUrl(t,c),r)}const u=this.getPathForUnlocalizedRoute(n);if(u!==null){const c=this.buildLocalizedPath(u,t,!1);return this.debugLog("branch=unlocalizedPath",{unlocalizedPath:u,path:c}),this.preserveQueryAndHash(this.applyBaseUrl(t,c),r)}const d=this.getCustomPathSegment(n,t);if(d!==null){const c=n.name?.toString()??s??"",f=c?G(c):"",p=c?M(c):"",m=this.ctx.globalLocaleRoutes,N=f.includes("/")&&m?.[f],b=p.includes("/")&&m?.[p],rt=N||b,nt=b?p:f;let F;if(rt){const C=H(nt),z=C.length>1?C.slice(0,-1).join("-"):"",J=z&&m?.[z]&&typeof m[z]=="object"&&!Array.isArray(m[z])?m[z]:null,lt=J?.[t]?y(J[t]):P("/",...C.slice(0,-1)),it=d.startsWith("/")?d.slice(1):d;F=P(lt,it)}else F=y(d);const D=this.buildLocalizedPath(F,t,!0);return this.debugLog("branch=customSegment",{customSegment:d,pathWithoutLocale:F,finalPath:D}),this.preserveQueryAndHash(this.applyBaseUrl(t,D),r)}const g=i??s;if(this.debugLog("before effectiveBaseName check",{baseName:i,inputName:s,effectiveBaseName:g,resolvedName:n.name?.toString()}),!g)return this.debugLog("branch=noBaseName",{return:"src"}),r;if(!l&&n.path&&n.path!=="/"&&n.name){const{pathWithoutLocale:c,baseRouteName:f}=this.getPathWithoutLocaleAndBaseName(n);if(c&&c!=="/"){const p=f&&c===f?P("/",x(f)):c,m=this.buildLocalizedPath(p,t,!1);return this.debugLog("branch=pathFromResolved",{pathWithoutLocale:c,baseRouteName:f,pathToUse:p,finalPath:m}),this.preserveQueryAndHash(this.applyBaseUrl(t,m),r)}}const R=h===s?g:s??g;this.debugLog("fallback build",{resolvedNameStr:h,inputName:s,baseNameForPath:R,targetLocale:t,hasParams:l});const B=this.buildLocalizedRouteName(R,t),L={...r,name:B,params:{...r.params}};if(l){let c=null;try{const f=this.ctx.router.resolve({name:R,params:r.params});if(f?.path){const p=f.path==="/"?"/":(()=>{const{pathWithoutLocale:b}=this.getPathWithoutLocale(f.path);return b&&b!=="/"?b:f.path})(),m=this.buildLocalizedPath(p,t,!1),N=this.applyBaseUrl(t,m);c=typeof N=="string"?N:N.path??m}}catch{c=this.buildPathFromBaseNameAndParams(R,r.params??{},t)}c&&(L.path=c,L.fullPath=c)}else{const c=j(R)?"/":P("/",x(R)),f=this.buildLocalizedPath(c,t,!1),p=this.applyBaseUrl(t,f),m=typeof p=="string"?p:p.path??f;this.debugLog("fallback !hasParams",{pathWithoutLocale:c,finalPath:f,pathStr:m}),L.path=m,L.fullPath=m}L.path&&delete L.name;const W=this.preserveQueryAndHash(this.applyBaseUrl(t,L),r);return this.debugLog("branch=fallbackNewRoute return",{baseName:i,targetName:B,hasParams:l,newRoutePath:L.path,outPath:typeof W=="string"?W:W.path}),W}extractLocaleFromPath(t){if(!t)return null;const a=t.split("?")[0]?.split("#")[0];if(!a||a==="/")return null;const s=a.split("/").filter(Boolean);if(s.length===0)return null;const r=s[0];return r&&this.ctx.locales.map(l=>l.code).includes(r)?r:null}getCurrentLocale(t,e){const a=this.ctx.strategy;if(this.ctx.hashMode){const l=e?.();return l||this.ctx.defaultLocale}if(a==="no_prefix"){const l=e?.();return l||this.ctx.defaultLocale}const s=t.path||t.fullPath||"";if(a==="prefix_and_default"&&(s==="/"||s==="")){const l=e?.();if(l)return l}if(t.params?.locale)return String(t.params.locale);const r=this.extractLocaleFromPath(s);if(r)return r;if(a==="prefix_except_default")return this.ctx.defaultLocale;const n=e?.();return n||this.ctx.defaultLocale}getPluginRouteName(t,e){if(this.ctx.disablePageLocales)return"general";const a=this.getRouteBaseName(t);return a||(t.name??"").toString().replace(this.getLocalizedRouteNamePrefix(),"").replace(new RegExp(`-${e}$`),"")}getCurrentLocaleName(t){const e=this.getCurrentLocale(t);return this.ctx.locales.find(s=>s.code===e)?.displayName??null}}exports.BasePathStrategy=Qt;exports.RouteResolver=ot;exports.buildLocalizedName=at;exports.buildUrl=$;exports.cleanDoubleSlashes=Q;exports.getCleanPath=K;exports.getLocaleFromPath=st;exports.getPathSegments=H;exports.getPathWithoutLocale=X;exports.getRouteBaseName=V;exports.isIndexRouteName=j;exports.isSamePath=Ct;exports.joinUrl=P;exports.lastPathSegment=qt;exports.nameKeyFirstSlash=G;exports.nameKeyLastSlash=M;exports.normalizePath=y;exports.normalizePathForCompare=$t;exports.parentKeyFromSlashKey=jt;exports.transformNameKeyToPath=x;exports.withLeadingSlash=O;exports.withoutLeadingSlash=w;
|
|
2
|
-
//# sourceMappingURL=base-strategy-CF5n6eGB.cjs.map
|