@i18n-micro/path-strategy 1.0.0
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/LICENSE +21 -0
- package/README.md +196 -0
- package/dist/base-strategy-B5mBf3XX.cjs +2 -0
- package/dist/base-strategy-B5mBf3XX.cjs.map +1 -0
- package/dist/base-strategy-DVqe8ehd.js +790 -0
- package/dist/base-strategy-DVqe8ehd.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +394 -0
- package/dist/index.mjs +45 -0
- package/dist/index.mjs.map +1 -0
- package/dist/no-prefix-strategy.cjs +2 -0
- package/dist/no-prefix-strategy.cjs.map +1 -0
- package/dist/no-prefix-strategy.d.ts +283 -0
- package/dist/no-prefix-strategy.mjs +40 -0
- package/dist/no-prefix-strategy.mjs.map +1 -0
- package/dist/prefix-and-default-strategy.cjs +2 -0
- package/dist/prefix-and-default-strategy.cjs.map +1 -0
- package/dist/prefix-and-default-strategy.d.ts +284 -0
- package/dist/prefix-and-default-strategy.mjs +129 -0
- package/dist/prefix-and-default-strategy.mjs.map +1 -0
- package/dist/prefix-except-default-strategy.cjs +2 -0
- package/dist/prefix-except-default-strategy.cjs.map +1 -0
- package/dist/prefix-except-default-strategy.d.ts +298 -0
- package/dist/prefix-except-default-strategy.mjs +245 -0
- package/dist/prefix-except-default-strategy.mjs.map +1 -0
- package/dist/prefix-strategy.cjs +2 -0
- package/dist/prefix-strategy.cjs.map +1 -0
- package/dist/prefix-strategy.d.ts +277 -0
- package/dist/prefix-strategy.mjs +40 -0
- package/dist/prefix-strategy.mjs.map +1 -0
- package/dist/types.cjs +2 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.ts +108 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +84 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { B as x, R as w, m as R, o as S, q as _, r as L, d as N } from "./base-strategy-DVqe8ehd.js";
|
|
2
|
+
import { PrefixPathStrategy as u } from "./prefix-strategy.mjs";
|
|
3
|
+
import { NoPrefixPathStrategy as n } from "./no-prefix-strategy.mjs";
|
|
4
|
+
import { PrefixExceptDefaultPathStrategy as a } from "./prefix-except-default-strategy.mjs";
|
|
5
|
+
import { PrefixAndDefaultPathStrategy as m } from "./prefix-and-default-strategy.mjs";
|
|
6
|
+
function d(e, r, o, t, f, i, s) {
|
|
7
|
+
return {
|
|
8
|
+
...e ? { name: e } : {},
|
|
9
|
+
path: r,
|
|
10
|
+
fullPath: o,
|
|
11
|
+
params: f ?? t.params ?? {},
|
|
12
|
+
query: i ?? t.query ?? {},
|
|
13
|
+
hash: t.hash ?? s ?? ""
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function g(e) {
|
|
17
|
+
switch (e.strategy) {
|
|
18
|
+
case "no_prefix":
|
|
19
|
+
return new n(e);
|
|
20
|
+
case "prefix":
|
|
21
|
+
return new u(e);
|
|
22
|
+
case "prefix_except_default":
|
|
23
|
+
return new a(e);
|
|
24
|
+
case "prefix_and_default":
|
|
25
|
+
return new m(e);
|
|
26
|
+
default:
|
|
27
|
+
return new a(e);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
x as BasePathStrategy,
|
|
32
|
+
n as NoPrefixPathStrategy,
|
|
33
|
+
m as PrefixAndDefaultPathStrategy,
|
|
34
|
+
a as PrefixExceptDefaultPathStrategy,
|
|
35
|
+
u as PrefixPathStrategy,
|
|
36
|
+
w as RouteResolver,
|
|
37
|
+
R as buildLocalizedName,
|
|
38
|
+
d as createLocalizedRouteObject,
|
|
39
|
+
g as createPathStrategy,
|
|
40
|
+
S as getLocaleFromPath,
|
|
41
|
+
_ as getPathWithoutLocale,
|
|
42
|
+
L as getRouteBaseName,
|
|
43
|
+
N as isIndexRouteName
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/core/builder.ts","../src/strategies/factory.ts"],"sourcesContent":["/**\n * Pure functions for building route object (merge params, query, hash).\n */\nimport type { RouteLike, ResolvedRouteLike } from './types'\n\n/**\n * Creates localized route object preserving params, query, hash from source.\n */\nexport function createLocalizedRouteObject(\n name: string | undefined,\n path: string,\n fullPath: string,\n source: RouteLike | ResolvedRouteLike,\n resolvedParams?: Record<string, unknown>,\n resolvedQuery?: Record<string, unknown>,\n resolvedHash?: string,\n): RouteLike {\n return {\n ...(name ? { name } : {}),\n path,\n fullPath,\n params: resolvedParams ?? source.params ?? {},\n query: resolvedQuery ?? source.query ?? {},\n hash: source.hash ?? resolvedHash ?? '',\n }\n}\n","import type { PathStrategy, PathStrategyContext } from '../core/types'\nimport { NoPrefixPathStrategy } from './no-prefix'\nimport { PrefixPathStrategy } from './prefix'\nimport { PrefixExceptDefaultPathStrategy } from './prefix-except-default'\nimport { PrefixAndDefaultPathStrategy } from './prefix-and-default'\n\n/**\n * Creates the appropriate path strategy instance for the given context.\n * Used when all strategies are bundled (e.g. tests, server). For runtime client,\n * use Nuxt alias #i18n-strategy to import only the selected strategy.\n */\nexport function createPathStrategy(ctx: PathStrategyContext): PathStrategy {\n switch (ctx.strategy) {\n case 'no_prefix':\n return new NoPrefixPathStrategy(ctx)\n case 'prefix':\n return new PrefixPathStrategy(ctx)\n case 'prefix_except_default':\n return new PrefixExceptDefaultPathStrategy(ctx)\n case 'prefix_and_default':\n return new PrefixAndDefaultPathStrategy(ctx)\n default:\n return new PrefixExceptDefaultPathStrategy(ctx)\n }\n}\n"],"names":["createLocalizedRouteObject","name","path","fullPath","source","resolvedParams","resolvedQuery","resolvedHash","createPathStrategy","ctx","NoPrefixPathStrategy","PrefixPathStrategy","PrefixExceptDefaultPathStrategy","PrefixAndDefaultPathStrategy"],"mappings":";;;;;AAQO,SAASA,EACdC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,GACW;AACX,SAAO;AAAA,IACL,GAAIN,IAAO,EAAE,MAAAA,EAAA,IAAS,CAAA;AAAA,IACtB,MAAAC;AAAA,IACA,UAAAC;AAAA,IACA,QAAQE,KAAkBD,EAAO,UAAU,CAAA;AAAA,IAC3C,OAAOE,KAAiBF,EAAO,SAAS,CAAA;AAAA,IACxC,MAAMA,EAAO,QAAQG,KAAgB;AAAA,EAAA;AAEzC;ACdO,SAASC,EAAmBC,GAAwC;AACzE,UAAQA,EAAI,UAAA;AAAA,IACV,KAAK;AACH,aAAO,IAAIC,EAAqBD,CAAG;AAAA,IACrC,KAAK;AACH,aAAO,IAAIE,EAAmBF,CAAG;AAAA,IACnC,KAAK;AACH,aAAO,IAAIG,EAAgCH,CAAG;AAAA,IAChD,KAAK;AACH,aAAO,IAAII,EAA6BJ,CAAG;AAAA,IAC7C;AACE,aAAO,IAAIG,EAAgCH,CAAG;AAAA,EAAA;AAEpD;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./base-strategy-B5mBf3XX.cjs");class o extends l.BasePathStrategy{buildLocalizedPath(e,a,t){return l.normalizePath(e)}buildLocalizedRouteName(e,a){return this.buildLocalizedName(e,a)}getCanonicalPath(e,a){const t=this.getCustomPathSegment(e,a);return t?t.startsWith("/")?t:`/${t}`:null}resolveLocaleFromPath(e){return null}getLocaleFromPath(e){return super.getLocaleFromPath(e)}getSwitchLocaleFallbackWhenNoRoute(e,a){return e}getRedirect(e,a){if(this.ctx.noPrefixRedirect===!1)return null;const t=this.getLocaleFromPath(e);if(!t)return null;const i=`/${t}`;let r=e.slice(i.length);return(!r||!r.startsWith("/"))&&(r="/"+(r||"")),l.cleanDoubleSlashes(r)||"/"}}exports.NoPrefixPathStrategy=o;exports.Strategy=o;
|
|
2
|
+
//# sourceMappingURL=no-prefix-strategy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-prefix-strategy.cjs","sources":["../src/strategies/no-prefix.ts"],"sourcesContent":["import type { ResolvedRouteLike, RouteLike } from '../core/types'\nimport { BasePathStrategy } from './base-strategy'\nimport { cleanDoubleSlashes } from 'ufo'\nimport { normalizePath } from '../utils/path'\n\nexport class NoPrefixPathStrategy extends BasePathStrategy {\n protected buildLocalizedPath(path: string, _locale: string, _isCustom: boolean): string {\n return 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 return segment.startsWith('/') ? segment : `/${segment}`\n }\n\n resolveLocaleFromPath(_path: string): string | null {\n return null\n }\n\n override getLocaleFromPath(path: string): string | null {\n return super.getLocaleFromPath(path)\n }\n\n /** NoPrefix: when router does not know the route — return source route unchanged. */\n protected override getSwitchLocaleFallbackWhenNoRoute(route: ResolvedRouteLike, _targetName: string): RouteLike | string {\n return route\n }\n\n /**\n * In no_prefix strategy, URL should not contain locale. If path starts with a locale segment,\n * redirect to path without it. Controlled by ctx.noPrefixRedirect (default: true).\n */\n getRedirect(currentPath: string, _targetLocale: string): string | null {\n if (this.ctx.noPrefixRedirect === false) return null\n const pathLocale = this.getLocaleFromPath(currentPath)\n if (!pathLocale) return null\n const prefix = `/${pathLocale}`\n let newPath = currentPath.slice(prefix.length)\n if (!newPath || !newPath.startsWith('/')) newPath = '/' + (newPath || '')\n return cleanDoubleSlashes(newPath) || '/'\n }\n}\n\n/** Alias for Nuxt alias consumption. */\nexport { NoPrefixPathStrategy as Strategy }\n"],"names":["NoPrefixPathStrategy","BasePathStrategy","path","_locale","_isCustom","normalizePath","baseName","locale","route","targetLocale","segment","_path","_targetName","currentPath","_targetLocale","pathLocale","prefix","newPath","cleanDoubleSlashes"],"mappings":"gIAKO,MAAMA,UAA6BC,EAAAA,gBAAiB,CAC/C,mBAAmBC,EAAcC,EAAiBC,EAA4B,CACtF,OAAOC,EAAAA,cAAcH,CAAI,CAC3B,CAEU,wBAAwBI,EAAkBC,EAAwB,CAC1E,OAAO,KAAK,mBAAmBD,EAAUC,CAAM,CACjD,CAES,iBAAiBC,EAA0BC,EAAqC,CACvF,MAAMC,EAAU,KAAK,qBAAqBF,EAAOC,CAAY,EAC7D,OAAKC,EACEA,EAAQ,WAAW,GAAG,EAAIA,EAAU,IAAIA,CAAO,GADjC,IAEvB,CAEA,sBAAsBC,EAA8B,CAClD,OAAO,IACT,CAES,kBAAkBT,EAA6B,CACtD,OAAO,MAAM,kBAAkBA,CAAI,CACrC,CAGmB,mCAAmCM,EAA0BI,EAAyC,CACvH,OAAOJ,CACT,CAMA,YAAYK,EAAqBC,EAAsC,CACrE,GAAI,KAAK,IAAI,mBAAqB,GAAO,OAAO,KAChD,MAAMC,EAAa,KAAK,kBAAkBF,CAAW,EACrD,GAAI,CAACE,EAAY,OAAO,KACxB,MAAMC,EAAS,IAAID,CAAU,GAC7B,IAAIE,EAAUJ,EAAY,MAAMG,EAAO,MAAM,EAC7C,OAAI,CAACC,GAAW,CAACA,EAAQ,WAAW,GAAG,KAAGA,EAAU,KAAOA,GAAW,KAC/DC,EAAAA,mBAAmBD,CAAO,GAAK,GACxC,CACF"}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { I18nRouteParams } from '@i18n-micro/types';
|
|
2
|
+
import { Locale } from '@i18n-micro/types';
|
|
3
|
+
import { Strategies } from '@i18n-micro/types';
|
|
4
|
+
|
|
5
|
+
declare abstract class BasePathStrategy implements PathStrategy {
|
|
6
|
+
protected ctx: PathStrategyContext;
|
|
7
|
+
protected resolver: RouteResolver;
|
|
8
|
+
constructor(ctx: PathStrategyContext);
|
|
9
|
+
setRouter(router: RouterAdapter): void;
|
|
10
|
+
getDefaultLocale(): string;
|
|
11
|
+
getLocales(): Locale[];
|
|
12
|
+
getStrategy(): PathStrategyContext['strategy'];
|
|
13
|
+
getLocalizedRouteNamePrefix(): string;
|
|
14
|
+
getGlobalLocaleRoutes(): PathStrategyContext['globalLocaleRoutes'];
|
|
15
|
+
getRouteLocales(): PathStrategyContext['routeLocales'];
|
|
16
|
+
getRoutesLocaleLinks(): PathStrategyContext['routesLocaleLinks'];
|
|
17
|
+
getNoPrefixRedirect(): boolean | undefined;
|
|
18
|
+
/** Strips localization prefix/suffix and returns the "base" route name for one locale. */
|
|
19
|
+
protected getBaseRouteName(route: RouteLike, locale: string): string | null;
|
|
20
|
+
/** Returns the base route name (without localized prefix/suffix) by trying all locales. */
|
|
21
|
+
getRouteBaseName(route: RouteLike): string | null;
|
|
22
|
+
/** Resolves target path for a locale, checking globalLocaleRoutes first. */
|
|
23
|
+
protected resolvePathForLocale(path: string, targetLocale: string): string;
|
|
24
|
+
protected buildLocalizedName(baseName: string, locale: string): string;
|
|
25
|
+
/** Builds path for target locale (strategy decides: with or without prefix). */
|
|
26
|
+
protected abstract buildLocalizedPath(path: string, locale: string, isCustom: boolean): string;
|
|
27
|
+
/** Builds localized route name for target locale. */
|
|
28
|
+
protected abstract buildLocalizedRouteName(baseName: string, locale: string): string;
|
|
29
|
+
protected getLocaleObject(code: string): Locale | undefined;
|
|
30
|
+
protected applyBaseUrl(localeCode: string, route: RouteLike | string): RouteLike | string;
|
|
31
|
+
/**
|
|
32
|
+
* Merges target route (strategy result) with query and hash from source route.
|
|
33
|
+
* Returns normalized RouteLike object.
|
|
34
|
+
*/
|
|
35
|
+
protected preserveQueryAndHash(target: RouteLike | string, source?: RouteLike | null): RouteLike | string;
|
|
36
|
+
protected resolvePathWithParams(path: string, params?: Record<string, unknown>): string;
|
|
37
|
+
protected getPathWithoutLocaleAndBaseName(route: ResolvedRouteLike): {
|
|
38
|
+
pathWithoutLocale: string;
|
|
39
|
+
baseRouteName: string | null;
|
|
40
|
+
};
|
|
41
|
+
/** Look up custom path segment for targetLocale in globalLocaleRoutes. */
|
|
42
|
+
protected getCustomPathSegment(route: ResolvedRouteLike, targetLocale: string): string | null;
|
|
43
|
+
protected getAllowedLocalesForRoute(route: ResolvedRouteLike): string[];
|
|
44
|
+
getCanonicalPath(_route: ResolvedRouteLike, _targetLocale: string): string | null;
|
|
45
|
+
protected getPathForUnlocalizedRouteByName(routeName: string): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* Try to resolve route by localized name. Returns RouteLike with query/hash from sourceRoute to preserve them.
|
|
48
|
+
*/
|
|
49
|
+
protected tryResolveByLocalizedName(routeName: string, targetLocale: string, sourceRoute?: RouteLike): RouteLike | null;
|
|
50
|
+
/**
|
|
51
|
+
* Try to resolve route by localized name with params. Returns RouteLike to preserve query/hash.
|
|
52
|
+
*/
|
|
53
|
+
protected tryResolveByLocalizedNameWithParams(routeName: string, targetLocale: string, params: Record<string, unknown>, sourceRoute?: RouteLike): RouteLike | null;
|
|
54
|
+
protected getPathForUnlocalizedRoute(route: ResolvedRouteLike): string | null;
|
|
55
|
+
/**
|
|
56
|
+
* Builds localized path from baseName + params when router does not have the route.
|
|
57
|
+
* Tries two conventions:
|
|
58
|
+
* 1) Hyphen form (Nuxt test-[id].vue → /test-:id): when single param key equals last baseName segment (e.g. test-id + id → test-:id).
|
|
59
|
+
* 2) Slash form (kebab→slash): path segments from baseName, last N replaced by :paramKey (e.g. test-id → /test/:id).
|
|
60
|
+
*/
|
|
61
|
+
protected buildPathFromBaseNameAndParams(baseName: string, params: Record<string, unknown>, targetLocale: string): string | null;
|
|
62
|
+
protected getPathWithoutLocale(path: string): {
|
|
63
|
+
pathWithoutLocale: string;
|
|
64
|
+
localeFromPath: string | null;
|
|
65
|
+
};
|
|
66
|
+
getLocaleFromPath(path: string): string | null;
|
|
67
|
+
abstract resolveLocaleFromPath(path: string): string | null;
|
|
68
|
+
/**
|
|
69
|
+
* Returns path to redirect to, or null if no redirect needed.
|
|
70
|
+
* Use in middleware: strategy.getRedirect(to.fullPath, detectedLocale)
|
|
71
|
+
*/
|
|
72
|
+
abstract getRedirect(currentPath: string, targetLocale: string): string | null;
|
|
73
|
+
/**
|
|
74
|
+
* Builds SEO attributes (canonical + hreflangs) from current route.
|
|
75
|
+
* Respects routeLocales: only allowed locales for this route get an hreflang entry.
|
|
76
|
+
* routesLocaleLinks is used when resolving the route key for routeLocales lookup.
|
|
77
|
+
*/
|
|
78
|
+
getSeoAttributes(currentRoute: ResolvedRouteLike): SeoAttributes;
|
|
79
|
+
/**
|
|
80
|
+
* Builds full URL (path + optional baseUrl for locale).
|
|
81
|
+
*/
|
|
82
|
+
protected buildFullUrl(localeCode: string, path: string): string;
|
|
83
|
+
/** When router knows neither targetName nor baseName — what to return (strategy may override). */
|
|
84
|
+
protected getSwitchLocaleFallbackWhenNoRoute(route: ResolvedRouteLike, targetName: string): RouteLike | string;
|
|
85
|
+
/**
|
|
86
|
+
* Default: baseName → buildLocalizedRouteName → hasRoute → applyBaseUrl; fallback to baseName.
|
|
87
|
+
*/
|
|
88
|
+
switchLocaleRoute(fromLocale: string, toLocale: string, route: ResolvedRouteLike, options: SwitchLocaleOptions): RouteLike | string;
|
|
89
|
+
/**
|
|
90
|
+
* Template Method: BaseStrategy knows "how" (normalize → delegate to strategy).
|
|
91
|
+
* Always returns RouteLike with path and fullPath (never a string).
|
|
92
|
+
*/
|
|
93
|
+
localeRoute(targetLocale: string, routeOrPath: RouteLike | string, currentRoute?: ResolvedRouteLike): RouteLike;
|
|
94
|
+
/** Normalizes resolveLocaleRoute result into RouteLike (path and fullPath always set). */
|
|
95
|
+
protected ensureRouteLike(value: RouteLike | string, source?: RouteLike | null): RouteLike;
|
|
96
|
+
/**
|
|
97
|
+
* Normalizes localeRoute input into a single structure (path string or route with resolved).
|
|
98
|
+
*/
|
|
99
|
+
protected normalizeRouteInput(routeOrPath: RouteLike | string, _currentRoute?: ResolvedRouteLike): NormalizedRouteInput;
|
|
100
|
+
/** Logging when ctx.debug (for localeRoute debugging). Disabled by default. */
|
|
101
|
+
private debugLog;
|
|
102
|
+
/**
|
|
103
|
+
* Default resolution: uses buildLocalizedPath and buildLocalizedRouteName.
|
|
104
|
+
* Strategies with different logic (e.g. prefix-except-default) override this method.
|
|
105
|
+
*/
|
|
106
|
+
protected resolveLocaleRoute(targetLocale: string, normalized: NormalizedRouteInput, _currentRoute?: ResolvedRouteLike): RouteLike | string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Custom path rules: route key -> locale -> path segment. false = unlocalized route. */
|
|
110
|
+
declare type GlobalLocaleRoutes = Record<string, Record<string, string> | false>;
|
|
111
|
+
|
|
112
|
+
declare interface HreflangTag {
|
|
113
|
+
rel: 'alternate';
|
|
114
|
+
href: string;
|
|
115
|
+
hreflang: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
declare class NoPrefixPathStrategy extends BasePathStrategy {
|
|
119
|
+
protected buildLocalizedPath(path: string, _locale: string, _isCustom: boolean): string;
|
|
120
|
+
protected buildLocalizedRouteName(baseName: string, locale: string): string;
|
|
121
|
+
getCanonicalPath(route: ResolvedRouteLike, targetLocale: string): string | null;
|
|
122
|
+
resolveLocaleFromPath(_path: string): string | null;
|
|
123
|
+
getLocaleFromPath(path: string): string | null;
|
|
124
|
+
/** NoPrefix: when router does not know the route — return source route unchanged. */
|
|
125
|
+
protected getSwitchLocaleFallbackWhenNoRoute(route: ResolvedRouteLike, _targetName: string): RouteLike | string;
|
|
126
|
+
/**
|
|
127
|
+
* In no_prefix strategy, URL should not contain locale. If path starts with a locale segment,
|
|
128
|
+
* redirect to path without it. Controlled by ctx.noPrefixRedirect (default: true).
|
|
129
|
+
*/
|
|
130
|
+
getRedirect(currentPath: string, _targetLocale: string): string | null;
|
|
131
|
+
}
|
|
132
|
+
export { NoPrefixPathStrategy }
|
|
133
|
+
export { NoPrefixPathStrategy as Strategy }
|
|
134
|
+
|
|
135
|
+
/** Normalized input for resolveLocaleRoute (template method). */
|
|
136
|
+
declare type NormalizedRouteInput = {
|
|
137
|
+
kind: 'path';
|
|
138
|
+
path: string;
|
|
139
|
+
} | {
|
|
140
|
+
kind: 'route';
|
|
141
|
+
inputName: string | null;
|
|
142
|
+
sourceRoute: RouteLike;
|
|
143
|
+
resolved: ResolvedRouteLike;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
declare interface PathStrategy {
|
|
147
|
+
/**
|
|
148
|
+
* Returns a route object to navigate to another locale from the current page.
|
|
149
|
+
*/
|
|
150
|
+
switchLocaleRoute(fromLocale: string, toLocale: string, route: ResolvedRouteLike, options: SwitchLocaleOptions): RouteLike | string;
|
|
151
|
+
/**
|
|
152
|
+
* Localizes the given route (object or string) for the target locale.
|
|
153
|
+
* Always returns RouteLike (path and fullPath set). Analogue of $localeRoute / resolveLocalizedRoute.
|
|
154
|
+
*/
|
|
155
|
+
localeRoute(targetLocale: string, routeOrPath: RouteLike | string, currentRoute?: ResolvedRouteLike): RouteLike;
|
|
156
|
+
/**
|
|
157
|
+
* Checks if there is a custom path for the given route in globalLocaleRoutes.
|
|
158
|
+
* Used by redirect logic. Returns a path or null.
|
|
159
|
+
*/
|
|
160
|
+
getCanonicalPath(route: ResolvedRouteLike, targetLocale: string): string | null;
|
|
161
|
+
/**
|
|
162
|
+
* Determines locale from URL path (strategy-specific).
|
|
163
|
+
* Returns locale code or null if path does not contain a locale (e.g. no_prefix).
|
|
164
|
+
*/
|
|
165
|
+
resolveLocaleFromPath(path: string): string | null;
|
|
166
|
+
/**
|
|
167
|
+
* Tries to determine locale from URL path (first segment).
|
|
168
|
+
* Used for initial state and redirect logic. Base implementation in BasePathStrategy.
|
|
169
|
+
*/
|
|
170
|
+
getLocaleFromPath(path: string): string | null;
|
|
171
|
+
/**
|
|
172
|
+
* Returns path to redirect to for the given current path and target locale, or null if no redirect needed.
|
|
173
|
+
* Use in middleware: const redirectPath = strategy.getRedirect(to.fullPath, detectedLocale)
|
|
174
|
+
*/
|
|
175
|
+
getRedirect(currentPath: string, targetLocale: string): string | null;
|
|
176
|
+
/**
|
|
177
|
+
* Returns SEO attributes (canonical, hreflangs) for useHead.
|
|
178
|
+
*/
|
|
179
|
+
getSeoAttributes(currentRoute: ResolvedRouteLike): SeoAttributes;
|
|
180
|
+
/**
|
|
181
|
+
* Sets the router adapter (e.g. when creating singleton and passing router later).
|
|
182
|
+
*/
|
|
183
|
+
setRouter(router: RouterAdapter): void;
|
|
184
|
+
getDefaultLocale(): string;
|
|
185
|
+
getLocales(): Locale[];
|
|
186
|
+
getStrategy(): Strategies;
|
|
187
|
+
getLocalizedRouteNamePrefix(): string;
|
|
188
|
+
getGlobalLocaleRoutes(): GlobalLocaleRoutes | undefined;
|
|
189
|
+
getRouteLocales(): Record<string, string[]> | undefined;
|
|
190
|
+
getRoutesLocaleLinks(): Record<string, string> | undefined;
|
|
191
|
+
getNoPrefixRedirect(): boolean | undefined;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
declare interface PathStrategyContext {
|
|
195
|
+
strategy: Strategies;
|
|
196
|
+
defaultLocale: string;
|
|
197
|
+
locales: Locale[];
|
|
198
|
+
localizedRouteNamePrefix: string;
|
|
199
|
+
globalLocaleRoutes?: GlobalLocaleRoutes;
|
|
200
|
+
routeLocales?: Record<string, string[]>;
|
|
201
|
+
routesLocaleLinks?: Record<string, string>;
|
|
202
|
+
includeDefaultLocaleRoute?: boolean;
|
|
203
|
+
noPrefixRedirect?: boolean;
|
|
204
|
+
debug?: boolean;
|
|
205
|
+
router: RouterAdapter;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Resolved route (path and fullPath required). */
|
|
209
|
+
declare interface ResolvedRouteLike extends RouteLike {
|
|
210
|
+
name: string | null;
|
|
211
|
+
path: string;
|
|
212
|
+
fullPath: string;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Route-like shape (compatible with vue-router). */
|
|
216
|
+
declare interface RouteLike {
|
|
217
|
+
name?: string | null;
|
|
218
|
+
path?: string;
|
|
219
|
+
params?: Record<string, unknown>;
|
|
220
|
+
query?: Record<string, unknown>;
|
|
221
|
+
hash?: string;
|
|
222
|
+
fullPath?: string;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
declare interface RouterAdapter {
|
|
226
|
+
hasRoute: (name: string) => boolean;
|
|
227
|
+
resolve: (to: RouteLike | string) => ResolvedRouteLike;
|
|
228
|
+
getRoutes?: () => unknown[];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
declare class RouteResolver {
|
|
232
|
+
private ctx;
|
|
233
|
+
constructor(ctx: PathStrategyContext);
|
|
234
|
+
/**
|
|
235
|
+
* Substitutes params into path template (:key, :key(), [...key]).
|
|
236
|
+
* Uses one combined regex per key to avoid creating multiple RegExp in a loop.
|
|
237
|
+
*/
|
|
238
|
+
resolvePathWithParams(path: string, params?: Record<string, unknown>): string;
|
|
239
|
+
/**
|
|
240
|
+
* Analyzes route: path without locale and base name (normalizer + route-name).
|
|
241
|
+
*/
|
|
242
|
+
private analyzeRoute;
|
|
243
|
+
/** Public access to route analysis (for strategies). */
|
|
244
|
+
getPathWithoutLocaleAndBaseName(route: ResolvedRouteLike): {
|
|
245
|
+
pathWithoutLocale: string;
|
|
246
|
+
baseRouteName: string | null;
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Lookup keys for config (same order for resolveCustomPath, getPathForUnlocalizedRoute, getAllowedLocalesForRoute).
|
|
250
|
+
*/
|
|
251
|
+
private getLookupKeys;
|
|
252
|
+
/**
|
|
253
|
+
* Resolves custom path for targetLocale from globalLocaleRoutes.
|
|
254
|
+
*/
|
|
255
|
+
resolveCustomPath(route: ResolvedRouteLike, targetLocale: string): string | null;
|
|
256
|
+
/**
|
|
257
|
+
* Unlocalized route (globalLocaleRoutes[key] === false) — returns path without locale.
|
|
258
|
+
*/
|
|
259
|
+
getPathForUnlocalizedRoute(route: ResolvedRouteLike): string | null;
|
|
260
|
+
/**
|
|
261
|
+
* Unlocalized by name (when no route object available).
|
|
262
|
+
*/
|
|
263
|
+
getPathForUnlocalizedRouteByName(routeName: string): string | null;
|
|
264
|
+
/**
|
|
265
|
+
* Allowed locales for route (routeLocales).
|
|
266
|
+
*/
|
|
267
|
+
getAllowedLocalesForRoute(route: ResolvedRouteLike): string[];
|
|
268
|
+
/**
|
|
269
|
+
* Parent path for nested route (parent key -> targetLocale path).
|
|
270
|
+
*/
|
|
271
|
+
getParentPathForNested(nameSegments: string[], targetLocale: string): string;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
declare interface SeoAttributes {
|
|
275
|
+
canonical?: string;
|
|
276
|
+
hreflangs?: HreflangTag[];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
declare interface SwitchLocaleOptions {
|
|
280
|
+
i18nRouteParams?: I18nRouteParams;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export { }
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { B as o, n as s, c as n } from "./base-strategy-DVqe8ehd.js";
|
|
2
|
+
class h extends o {
|
|
3
|
+
buildLocalizedPath(t, a, e) {
|
|
4
|
+
return s(t);
|
|
5
|
+
}
|
|
6
|
+
buildLocalizedRouteName(t, a) {
|
|
7
|
+
return this.buildLocalizedName(t, a);
|
|
8
|
+
}
|
|
9
|
+
getCanonicalPath(t, a) {
|
|
10
|
+
const e = this.getCustomPathSegment(t, a);
|
|
11
|
+
return e ? e.startsWith("/") ? e : `/${e}` : null;
|
|
12
|
+
}
|
|
13
|
+
resolveLocaleFromPath(t) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
getLocaleFromPath(t) {
|
|
17
|
+
return super.getLocaleFromPath(t);
|
|
18
|
+
}
|
|
19
|
+
/** NoPrefix: when router does not know the route — return source route unchanged. */
|
|
20
|
+
getSwitchLocaleFallbackWhenNoRoute(t, a) {
|
|
21
|
+
return t;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* In no_prefix strategy, URL should not contain locale. If path starts with a locale segment,
|
|
25
|
+
* redirect to path without it. Controlled by ctx.noPrefixRedirect (default: true).
|
|
26
|
+
*/
|
|
27
|
+
getRedirect(t, a) {
|
|
28
|
+
if (this.ctx.noPrefixRedirect === !1) return null;
|
|
29
|
+
const e = this.getLocaleFromPath(t);
|
|
30
|
+
if (!e) return null;
|
|
31
|
+
const l = `/${e}`;
|
|
32
|
+
let r = t.slice(l.length);
|
|
33
|
+
return (!r || !r.startsWith("/")) && (r = "/" + (r || "")), n(r) || "/";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
h as NoPrefixPathStrategy,
|
|
38
|
+
h as Strategy
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=no-prefix-strategy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-prefix-strategy.mjs","sources":["../src/strategies/no-prefix.ts"],"sourcesContent":["import type { ResolvedRouteLike, RouteLike } from '../core/types'\nimport { BasePathStrategy } from './base-strategy'\nimport { cleanDoubleSlashes } from 'ufo'\nimport { normalizePath } from '../utils/path'\n\nexport class NoPrefixPathStrategy extends BasePathStrategy {\n protected buildLocalizedPath(path: string, _locale: string, _isCustom: boolean): string {\n return 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 return segment.startsWith('/') ? segment : `/${segment}`\n }\n\n resolveLocaleFromPath(_path: string): string | null {\n return null\n }\n\n override getLocaleFromPath(path: string): string | null {\n return super.getLocaleFromPath(path)\n }\n\n /** NoPrefix: when router does not know the route — return source route unchanged. */\n protected override getSwitchLocaleFallbackWhenNoRoute(route: ResolvedRouteLike, _targetName: string): RouteLike | string {\n return route\n }\n\n /**\n * In no_prefix strategy, URL should not contain locale. If path starts with a locale segment,\n * redirect to path without it. Controlled by ctx.noPrefixRedirect (default: true).\n */\n getRedirect(currentPath: string, _targetLocale: string): string | null {\n if (this.ctx.noPrefixRedirect === false) return null\n const pathLocale = this.getLocaleFromPath(currentPath)\n if (!pathLocale) return null\n const prefix = `/${pathLocale}`\n let newPath = currentPath.slice(prefix.length)\n if (!newPath || !newPath.startsWith('/')) newPath = '/' + (newPath || '')\n return cleanDoubleSlashes(newPath) || '/'\n }\n}\n\n/** Alias for Nuxt alias consumption. */\nexport { NoPrefixPathStrategy as Strategy }\n"],"names":["NoPrefixPathStrategy","BasePathStrategy","path","_locale","_isCustom","normalizePath","baseName","locale","route","targetLocale","segment","_path","_targetName","currentPath","_targetLocale","pathLocale","prefix","newPath","cleanDoubleSlashes"],"mappings":";AAKO,MAAMA,UAA6BC,EAAiB;AAAA,EAC/C,mBAAmBC,GAAcC,GAAiBC,GAA4B;AACtF,WAAOC,EAAcH,CAAI;AAAA,EAC3B;AAAA,EAEU,wBAAwBI,GAAkBC,GAAwB;AAC1E,WAAO,KAAK,mBAAmBD,GAAUC,CAAM;AAAA,EACjD;AAAA,EAES,iBAAiBC,GAA0BC,GAAqC;AACvF,UAAMC,IAAU,KAAK,qBAAqBF,GAAOC,CAAY;AAC7D,WAAKC,IACEA,EAAQ,WAAW,GAAG,IAAIA,IAAU,IAAIA,CAAO,KADjC;AAAA,EAEvB;AAAA,EAEA,sBAAsBC,GAA8B;AAClD,WAAO;AAAA,EACT;AAAA,EAES,kBAAkBT,GAA6B;AACtD,WAAO,MAAM,kBAAkBA,CAAI;AAAA,EACrC;AAAA;AAAA,EAGmB,mCAAmCM,GAA0BI,GAAyC;AACvH,WAAOJ;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,YAAYK,GAAqBC,GAAsC;AACrE,QAAI,KAAK,IAAI,qBAAqB,GAAO,QAAO;AAChD,UAAMC,IAAa,KAAK,kBAAkBF,CAAW;AACrD,QAAI,CAACE,EAAY,QAAO;AACxB,UAAMC,IAAS,IAAID,CAAU;AAC7B,QAAIE,IAAUJ,EAAY,MAAMG,EAAO,MAAM;AAC7C,YAAI,CAACC,KAAW,CAACA,EAAQ,WAAW,GAAG,OAAGA,IAAU,OAAOA,KAAW,MAC/DC,EAAmBD,CAAO,KAAK;AAAA,EACxC;AACF;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./base-strategy-B5mBf3XX.cjs");class B extends e.BasePathStrategy{buildLocalizedPath(t,h,s){return e.joinUrl(h,e.normalizePath(t))}buildLocalizedRouteName(t,h){return this.buildLocalizedName(t,h)}switchLocaleRoute(t,h,s,l){const o=this.getBaseRouteName(s,t);if(!o)return s;const i=this.buildLocalizedName(o,h);if(this.ctx.router.hasRoute(i)){const c=l.i18nRouteParams?.[h]||{},r={...s.params||{},...c};return delete r.locale,this.applyBaseUrl(h,{name:i,params:r,query:s.query,hash:s.hash})}return{...s,name:i}}resolveLocaleRoute(t,h,s){if(h.kind==="path"){const a=this.resolvePathForLocale(h.path,t),n=`/${t}`;return this.applyBaseUrl(t,e.joinUrl(n,e.withLeadingSlash(a)))}const{inputName:l,sourceRoute:o,resolved:i}=h;if(l){const a=this.getPathForUnlocalizedRouteByName(l);if(a!==null)return a}const c=o.params&&Object.keys(o.params??{}).length>0;if(l&&c){const a=this.tryResolveByLocalizedNameWithParams(l,t,o.params??{},o);if(a!==null){const n=a.path??"",{pathWithoutLocale:u}=this.getPathWithoutLocale(n),m=u==="/"||u===""?`/${t}`:e.joinUrl(`/${t}`,e.withLeadingSlash(u)),d=e.buildUrl(m,a.query,a.hash),y={...a,path:m,fullPath:d};return this.applyBaseUrl(t,y)}}const r=this.getPathForUnlocalizedRoute(i);if(r!==null)return this.applyBaseUrl(t,r);const W=this.getCustomPathSegment(i,t);if(W!==null){const a=`/${t}`;return this.applyBaseUrl(t,e.joinUrl(a,e.withLeadingSlash(W)))}const p=this.getRouteBaseName(i)??l??i.name?.toString()??null;if(l&&!c){let a=this.tryResolveByLocalizedName(l,t,o);const n=this.getLocalizedRouteNamePrefix();if(a===null&&p!=null&&p!==l&&l.startsWith(n)&&(a=this.tryResolveByLocalizedName(p,t,o)),a!==null){const u=a.path??"",{pathWithoutLocale:m}=this.getPathWithoutLocale(u),d=m==="/"||m===""?`/${t}`:e.joinUrl(`/${t}`,e.withLeadingSlash(m)),y=e.buildUrl(d,a.query,a.hash),R={...a,path:d,fullPath:y};return this.applyBaseUrl(t,R)}}if(i.path&&i.path!=="/"&&i.name){const{pathWithoutLocale:a}=this.getPathWithoutLocaleAndBaseName(i);if(a&&a!=="/")return this.applyBaseUrl(t,e.joinUrl(`/${t}`,e.withLeadingSlash(a)))}const N=s?this.detectLocaleFromName(s.name):this.detectLocaleFromName(i.name),P=N?this.getBaseRouteName(i,N):p;if(!P){const{pathWithoutLocale:a}=this.getPathWithoutLocale(i.path??"/"),n=a==="/"||a===""?`/${t}`:e.joinUrl(`/${t}`,e.withLeadingSlash(a)),u=e.buildUrl(n,o.query,o.hash);return this.applyBaseUrl(t,{...o,path:n,fullPath:u})}const S=this.buildLocalizedName(P,t),g=e.isIndexRouteName(P)?"/":e.joinUrl("/",e.transformNameKeyToPath(P)),U=e.joinUrl(`/${t}`,e.withLeadingSlash(g)),f=this.applyBaseUrl(t,U),L=typeof f=="string"?f:f.path??U,b={name:S,path:L,fullPath:L,params:{...i.params,...o.params},query:{...i.query,...o.query},hash:o.hash??i.hash};return this.applyBaseUrl(t,b)}getCanonicalPath(t,h){const s=this.getCustomPathSegment(t,h);return s?e.joinUrl(`/${h}`,e.withLeadingSlash(s)):null}detectLocaleFromName(t){if(!t)return null;for(const h of this.ctx.locales)if(t.endsWith(`-${h.code}`))return h.code;return null}resolveLocaleFromPath(t){const{localeFromPath:h}=this.getPathWithoutLocale(t);return h}getRedirect(t,h){const{pathWithoutLocale:s,localeFromPath:l}=this.getPathWithoutLocale(t),o=this.ctx.globalLocaleRoutes;if(o&&l!==null){const r=s==="/"?"/":e.withoutLeadingSlash(s);if(o[s]===!1||o[r]===!1)return e.normalizePathForCompare(s==="/"?"/":s)}const i=this.buildPathWithPrefix(s,h),c=e.getCleanPath(t);return l===h&&e.isSamePath(c,i)?null:i}buildPathWithPrefix(t,h){const s=this.resolvePathForLocale(t,h);return s==="/"||s===""?`/${h}`:e.joinUrl(`/${h}`,s)}}exports.PrefixAndDefaultPathStrategy=B;exports.Strategy=B;
|
|
2
|
+
//# sourceMappingURL=prefix-and-default-strategy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefix-and-default-strategy.cjs","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 const targetName = this.buildLocalizedName(baseName, toLocale)\n\n if (this.ctx.router.hasRoute(targetName)) {\n const i18nParams = options.i18nRouteParams?.[toLocale] || {}\n const newParams = { ...(route.params || {}), ...i18nParams }\n delete (newParams as Record<string, unknown>).locale\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 return { ...route, name: targetName }\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/** Alias for Nuxt alias consumption. */\nexport { PrefixAndDefaultPathStrategy as Strategy }\n"],"names":["PrefixAndDefaultPathStrategy","BasePathStrategy","path","locale","_isCustom","joinUrl","normalizePath","baseName","fromLocale","toLocale","route","options","targetName","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"],"mappings":"gIAUO,MAAMA,UAAqCC,EAAAA,gBAAiB,CACvD,mBAAmBC,EAAcC,EAAgBC,EAA4B,CACrF,OAAOC,UAAQF,EAAQG,EAAAA,cAAcJ,CAAI,CAAC,CAC5C,CAEU,wBAAwBK,EAAkBJ,EAAwB,CAC1E,OAAO,KAAK,mBAAmBI,EAAUJ,CAAM,CACjD,CAES,kBACPK,EACAC,EACAC,EACAC,EACoB,CACpB,MAAMJ,EAAW,KAAK,iBAAiBG,EAAOF,CAAU,EACxD,GAAI,CAACD,EAAU,OAAOG,EAEtB,MAAME,EAAa,KAAK,mBAAmBL,EAAUE,CAAQ,EAE7D,GAAI,KAAK,IAAI,OAAO,SAASG,CAAU,EAAG,CACxC,MAAMC,EAAaF,EAAQ,kBAAkBF,CAAQ,GAAK,CAAA,EACpDK,EAAY,CAAE,GAAIJ,EAAM,QAAU,CAAA,EAAK,GAAGG,CAAA,EAChD,cAAQC,EAAsC,O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