@i18n-micro/path-strategy 1.0.3 → 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.
Files changed (35) hide show
  1. package/dist/base-strategy-BuHeTv1K.cjs +2 -0
  2. package/dist/base-strategy-BuHeTv1K.cjs.map +1 -0
  3. package/dist/base-strategy-Cf39XK8k.js +926 -0
  4. package/dist/base-strategy-Cf39XK8k.js.map +1 -0
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.ts +134 -4
  8. package/dist/index.mjs +8 -8
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/no-prefix-strategy.cjs +1 -1
  11. package/dist/no-prefix-strategy.cjs.map +1 -1
  12. package/dist/no-prefix-strategy.d.ts +100 -4
  13. package/dist/no-prefix-strategy.mjs +42 -22
  14. package/dist/no-prefix-strategy.mjs.map +1 -1
  15. package/dist/prefix-and-default-strategy.cjs +1 -1
  16. package/dist/prefix-and-default-strategy.cjs.map +1 -1
  17. package/dist/prefix-and-default-strategy.d.ts +97 -4
  18. package/dist/prefix-and-default-strategy.mjs +101 -84
  19. package/dist/prefix-and-default-strategy.mjs.map +1 -1
  20. package/dist/prefix-except-default-strategy.cjs +1 -1
  21. package/dist/prefix-except-default-strategy.cjs.map +1 -1
  22. package/dist/prefix-except-default-strategy.d.ts +98 -4
  23. package/dist/prefix-except-default-strategy.mjs +248 -177
  24. package/dist/prefix-except-default-strategy.mjs.map +1 -1
  25. package/dist/prefix-strategy.cjs +1 -1
  26. package/dist/prefix-strategy.cjs.map +1 -1
  27. package/dist/prefix-strategy.d.ts +97 -4
  28. package/dist/prefix-strategy.mjs +35 -14
  29. package/dist/prefix-strategy.mjs.map +1 -1
  30. package/dist/types.d.ts +46 -1
  31. package/package.json +2 -2
  32. package/dist/base-strategy-B5mBf3XX.cjs +0 -2
  33. package/dist/base-strategy-B5mBf3XX.cjs.map +0 -1
  34. package/dist/base-strategy-DVqe8ehd.js +0 -790
  35. package/dist/base-strategy-DVqe8ehd.js.map +0 -1
@@ -1,194 +1,244 @@
1
- import { B as I, n as S, j as u, b as R, l as C, d as T, t as q, c as k, w as $, a as z, g as F, i as Q, e as j, p as g, f as O } from "./base-strategy-DVqe8ehd.js";
2
- class E extends I {
1
+ import { B as K, n as R, j as m, b as F, l as C, d as I, t as T, c as b, w as z, a as k, g, i as U, e as j, p as B, f as D } from "./base-strategy-Cf39XK8k.js";
2
+ class L extends K {
3
3
  /**
4
4
  * For this strategy a prefix is required for all non-default locales,
5
5
  * unless includeDefaultLocaleRoute is explicitly enabled.
6
6
  */
7
7
  shouldHavePrefix(t) {
8
- return this.ctx.includeDefaultLocaleRoute ? !0 : t !== this.ctx.defaultLocale;
9
- }
10
- buildLocalizedPath(t, s, e) {
11
- return this.shouldHavePrefix(s) ? u(s, S(t)) : S(t);
12
- }
13
- buildLocalizedRouteName(t, s) {
14
- return this.shouldHavePrefix(s) ? this.buildLocalizedName(t, s) : t;
15
- }
16
- switchLocaleRoute(t, s, e, n) {
17
- const a = this.getBaseRouteName(e, t);
18
- if (!a) return e;
19
- const h = this.shouldHavePrefix(s) ? this.buildLocalizedName(a, s) : a;
20
- if (this.ctx.router.hasRoute(h)) {
21
- const c = n.i18nRouteParams?.[s] || {}, p = { ...e.params || {}, ...c };
22
- delete p.locale;
23
- const v = {
24
- name: h,
8
+ if (this.ctx.includeDefaultLocaleRoute) return !0;
9
+ if (t === this.ctx.defaultLocale) return !1;
10
+ const a = this.ctx.locales.find((e) => e.code === t);
11
+ return !(a?.baseUrl && a?.baseDefault);
12
+ }
13
+ buildLocalizedPath(t, a, e) {
14
+ return this.shouldHavePrefix(a) ? m(a, R(t)) : R(t);
15
+ }
16
+ buildLocalizedRouteName(t, a) {
17
+ return this.shouldHavePrefix(a) ? this.buildLocalizedName(t, a) : t;
18
+ }
19
+ switchLocaleRoute(t, a, e, h) {
20
+ const s = this.getBaseRouteName(e, t);
21
+ if (!s) return e;
22
+ let r;
23
+ if (this.shouldHavePrefix(a)) {
24
+ const i = this.buildLocalizedName(s, a), p = `${this.getLocalizedRouteNamePrefix()}${s}`;
25
+ r = this.ctx.router.hasRoute(i) ? i : p;
26
+ } else
27
+ r = s;
28
+ if (this.ctx.router.hasRoute(r)) {
29
+ const i = h.i18nRouteParams?.[a] || {}, p = { ...e.params || {}, ...i };
30
+ this.shouldHavePrefix(a) ? p.locale = a : delete p.locale;
31
+ const S = this.ctx.router.resolve({ name: r, params: p }), N = {
32
+ name: r,
25
33
  params: p,
34
+ path: S?.path,
35
+ fullPath: S?.fullPath,
26
36
  query: e.query,
27
37
  hash: e.hash
28
38
  };
29
- return this.applyBaseUrl(s, v);
39
+ return this.applyBaseUrl(a, N);
30
40
  }
31
- return { ...e, name: h };
32
- }
33
- resolveLocaleRoute(t, s, e) {
34
- if (s.kind === "path") {
35
- const o = this.resolvePathForLocale(s.path, t);
36
- if (!this.shouldHavePrefix(t)) return this.applyBaseUrl(t, o);
37
- const f = u(t, o);
38
- return this.applyBaseUrl(t, f);
41
+ const o = e.path?.replace(new RegExp(`^/${t}`), "") || "/", P = this.buildLocalizedPath(o, a, !1);
42
+ return this.applyBaseUrl(a, { path: P, query: e.query, hash: e.hash });
43
+ }
44
+ resolveLocaleRoute(t, a, e) {
45
+ if (a.kind === "path") {
46
+ const l = this.resolvePathForLocale(a.path, t);
47
+ if (!this.shouldHavePrefix(t)) return this.applyBaseUrl(t, l);
48
+ const u = m(t, l);
49
+ return this.applyBaseUrl(t, u);
39
50
  }
40
- const { inputName: n, sourceRoute: a, resolved: h } = s;
41
- if (n) {
42
- const o = this.getPathForUnlocalizedRouteByName(n);
43
- if (o !== null) return this.preserveQueryAndHash(o, a);
44
- const l = "/" + R(n), m = {
45
- name: n,
46
- path: l,
47
- fullPath: l,
48
- params: a.params ?? {}
49
- }, i = this.getCustomPathSegment(m, t);
50
- if (i !== null) {
51
- const r = this.getNestedRouteInfo(n);
52
- let y;
53
- if (r) {
54
- const d = this.getParentPathForTarget(r.parentKey, r.keyWithSlash, t, e), N = i.startsWith("/") ? i.slice(1) : i;
55
- y = d ? u(d, N) : S(i);
51
+ const { inputName: h, sourceRoute: s, resolved: r } = a;
52
+ if (h) {
53
+ const l = this.getPathForUnlocalizedRouteByName(h);
54
+ if (l !== null) return this.preserveQueryAndHash(l, s);
55
+ const c = `/${F(h)}`, y = {
56
+ name: h,
57
+ path: c,
58
+ fullPath: c,
59
+ params: s.params ?? {}
60
+ }, n = this.getCustomPathSegment(y, t);
61
+ if (n !== null) {
62
+ const f = this.getNestedRouteInfo(h);
63
+ let d;
64
+ if (f) {
65
+ const v = this.getParentPathForTarget(f.parentKey, f.keyWithSlash, t, e), W = n.startsWith("/") ? n.slice(1) : n;
66
+ d = v ? m(v, W) : R(n);
56
67
  } else
57
- y = S(i);
68
+ d = R(n);
58
69
  if (!this.shouldHavePrefix(t))
59
- return this.preserveQueryAndHash(this.applyBaseUrl(t, y), a);
60
- const P = u(t, y);
61
- return this.preserveQueryAndHash(this.applyBaseUrl(t, P), a);
70
+ return this.preserveQueryAndHash(this.applyBaseUrl(t, d), s);
71
+ const x = m(t, d);
72
+ return this.preserveQueryAndHash(this.applyBaseUrl(t, x), s);
62
73
  }
63
74
  }
64
- const c = a.params && Object.keys(a.params ?? {}).length > 0;
65
- if (n && c) {
66
- const o = this.tryResolveByLocalizedNameWithParams(
67
- n,
68
- t,
69
- a.params ?? {},
70
- a
71
- );
72
- if (o !== null) {
73
- const f = this.applyBaseUrl(t, o);
74
- return this.preserveQueryAndHash(f, a);
75
+ const o = s.params && Object.keys(s.params ?? {}).length > 0;
76
+ if (h && o) {
77
+ if (!this.shouldHavePrefix(t) && this.ctx.router.hasRoute(h)) {
78
+ const u = this.ctx.router.resolve({
79
+ name: h,
80
+ params: s.params,
81
+ query: s.query,
82
+ hash: s.hash
83
+ });
84
+ if (u?.path && u.path !== "/") {
85
+ const c = {
86
+ name: h,
87
+ path: u.path,
88
+ fullPath: u.fullPath,
89
+ params: u.params,
90
+ query: u.query ?? s.query,
91
+ hash: u.hash ?? s.hash
92
+ };
93
+ return this.preserveQueryAndHash(this.applyBaseUrl(t, c), s);
94
+ }
95
+ }
96
+ const l = this.tryResolveByLocalizedNameWithParams(h, t, s.params ?? {}, s);
97
+ if (l !== null) {
98
+ const u = this.applyBaseUrl(t, l);
99
+ return this.preserveQueryAndHash(u, s);
75
100
  }
76
101
  }
77
- if (h.name != null) {
78
- const o = this.getPathForUnlocalizedRoute(h);
79
- if (o !== null)
80
- return this.preserveQueryAndHash(this.applyBaseUrl(t, o), a);
81
- const f = this.getCustomPathSegment(h, t);
82
- if (f !== null) {
83
- const l = h.name?.toString() ?? n ?? "", m = l ? this.getNestedRouteInfo(l) : null;
84
- let i;
85
- if (m) {
86
- const y = this.getParentPathForTarget(m.parentKey, m.keyWithSlash, t, e), P = f.startsWith("/") ? f.slice(1) : f;
87
- i = u(y, P);
102
+ if (r.name != null) {
103
+ const l = this.getPathForUnlocalizedRoute(r);
104
+ if (l !== null)
105
+ return this.preserveQueryAndHash(this.applyBaseUrl(t, l), s);
106
+ const u = this.getCustomPathSegment(r, t);
107
+ if (u !== null) {
108
+ const c = r.name?.toString() ?? h ?? "", y = c ? this.getNestedRouteInfo(c) : null;
109
+ let n;
110
+ if (y) {
111
+ const d = this.getParentPathForTarget(y.parentKey, y.keyWithSlash, t, e), x = u.startsWith("/") ? u.slice(1) : u;
112
+ n = m(d, x);
88
113
  } else
89
- i = S(f);
114
+ n = R(u);
90
115
  if (!this.shouldHavePrefix(t))
91
- return this.preserveQueryAndHash(this.applyBaseUrl(t, i), a);
92
- const r = u(t, i);
93
- return this.preserveQueryAndHash(this.applyBaseUrl(t, r), a);
116
+ return this.preserveQueryAndHash(this.applyBaseUrl(t, n), s);
117
+ const f = m(t, n);
118
+ return this.preserveQueryAndHash(this.applyBaseUrl(t, f), s);
94
119
  }
95
- if (h.path && h.path !== "/" && h.name) {
96
- const { pathWithoutLocale: l, baseRouteName: m } = this.getPathWithoutLocaleAndBaseName(h), i = this.getCustomPathSegment(h, t), r = m ? this.getNestedRouteInfo(m) : null, y = !!r;
97
- let P;
98
- if (i !== null && y && r) {
99
- const d = this.getParentPathForTarget(r.parentKey, r.keyWithSlash, t, e), N = i.startsWith("/") ? i.slice(1) : i;
100
- P = u(d, N);
101
- } else if (y && i === null && l && l !== "/" && r) {
102
- const d = this.getParentPathForTarget(r.parentKey, r.keyWithSlash, t, e), N = C(l);
103
- P = d ? u(d, N) : l !== "/" ? l : null;
120
+ if (r.path && r.path !== "/" && r.name) {
121
+ const { pathWithoutLocale: c, baseRouteName: y } = this.getPathWithoutLocaleAndBaseName(r), n = this.getCustomPathSegment(r, t), f = y ? this.getNestedRouteInfo(y) : null, d = !!f;
122
+ let x;
123
+ if (n !== null && d && f) {
124
+ const v = this.getParentPathForTarget(f.parentKey, f.keyWithSlash, t, e), W = n.startsWith("/") ? n.slice(1) : n;
125
+ x = m(v, W);
126
+ } else if (d && n === null && c && c !== "/" && f) {
127
+ const v = this.getParentPathForTarget(f.parentKey, f.keyWithSlash, t, e), W = C(c);
128
+ x = v ? m(v, W) : c !== "/" ? c : null;
104
129
  } else
105
- P = i !== null && !y ? S(i) : l && l !== "/" ? l : null;
106
- if (P) {
107
- const d = this.detectLocaleFromName(h.name), N = d ? this.getBaseRouteName(h, d) : h.name ? this.getRouteBaseName(h) : null, U = N ? this.shouldHavePrefix(t) ? this.buildLocalizedName(N, t) : N.toString() : void 0, A = this.shouldHavePrefix(t) ? u(t, P) : P, K = {
108
- ...U ? { name: U } : {},
109
- path: A,
110
- fullPath: A,
111
- params: { ...h.params, ...a.params },
112
- query: { ...h.query, ...a.query },
113
- hash: a.hash ?? h.hash
130
+ x = n !== null && !d ? R(n) : c && c !== "/" ? c : null;
131
+ if (x) {
132
+ const v = this.detectLocaleFromName(r.name), W = v ? this.getBaseRouteName(r, v) : r.name ? this.getRouteBaseName(r) : null, A = W ? this.shouldHavePrefix(t) ? this.buildLocalizedName(W, t) : W.toString() : void 0, $ = this.shouldHavePrefix(t) ? m(t, x) : x, w = {
133
+ ...A ? { name: A } : {},
134
+ path: $,
135
+ fullPath: $,
136
+ params: { ...r.params, ...s.params },
137
+ query: { ...r.query, ...s.query },
138
+ hash: s.hash ?? r.hash
114
139
  };
115
- return this.preserveQueryAndHash(this.applyBaseUrl(t, K), a);
140
+ return this.preserveQueryAndHash(this.applyBaseUrl(t, w), s);
116
141
  }
117
142
  }
118
143
  }
119
- if (n) {
120
- const f = "/" + R(n), l = {
121
- name: n,
122
- path: f,
123
- fullPath: f,
124
- params: a.params ?? {}
125
- }, m = this.getCustomPathSegment(l, t);
126
- if (m !== null) {
127
- const i = this.getNestedRouteInfo(n);
128
- let r;
129
- if (i) {
130
- const P = this.getParentPathForTarget(i.parentKey, i.keyWithSlash, t, e), d = m.startsWith("/") ? m.slice(1) : m;
131
- r = u(P || "/", d);
144
+ if (h) {
145
+ const u = `/${F(h)}`, c = {
146
+ name: h,
147
+ path: u,
148
+ fullPath: u,
149
+ params: s.params ?? {}
150
+ }, y = this.getCustomPathSegment(c, t);
151
+ if (y !== null) {
152
+ const n = this.getNestedRouteInfo(h);
153
+ let f;
154
+ if (n) {
155
+ const x = this.getParentPathForTarget(n.parentKey, n.keyWithSlash, t, e), v = y.startsWith("/") ? y.slice(1) : y;
156
+ f = m(x || "/", v);
132
157
  } else
133
- r = S(m);
158
+ f = R(y);
134
159
  if (!this.shouldHavePrefix(t))
135
- return this.preserveQueryAndHash(this.applyBaseUrl(t, r), a);
136
- const y = u(t, r);
137
- return this.preserveQueryAndHash(this.applyBaseUrl(t, y), a);
160
+ return this.preserveQueryAndHash(this.applyBaseUrl(t, f), s);
161
+ const d = m(t, f);
162
+ return this.preserveQueryAndHash(this.applyBaseUrl(t, d), s);
138
163
  }
139
164
  }
140
- if (n && !c) {
141
- const o = this.tryResolveByLocalizedName(n, t, a);
142
- if (o !== null) return this.preserveQueryAndHash(this.applyBaseUrl(t, o), a);
165
+ if (h && !o) {
166
+ if (this.shouldHavePrefix(t)) {
167
+ const l = this.tryResolveByLocalizedName(h, t, s);
168
+ if (l !== null) return this.preserveQueryAndHash(this.applyBaseUrl(t, l), s);
169
+ } else if (this.ctx.router.hasRoute(h)) {
170
+ const l = this.ctx.router.resolve({
171
+ name: h,
172
+ params: s.params,
173
+ query: s.query,
174
+ hash: s.hash
175
+ });
176
+ if (l?.path)
177
+ return this.preserveQueryAndHash(
178
+ this.applyBaseUrl(t, {
179
+ name: h,
180
+ path: l.path,
181
+ fullPath: l.fullPath,
182
+ params: l.params,
183
+ query: l.query ?? s.query,
184
+ hash: l.hash ?? s.hash
185
+ }),
186
+ s
187
+ );
188
+ }
143
189
  }
144
- const p = e ? this.detectLocaleFromName(e.name) : this.detectLocaleFromName(h.name), v = p ? this.getBaseRouteName(h, p) : h.name ?? null;
145
- if (!v) return a;
146
- const x = this.shouldHavePrefix(t) ? this.buildLocalizedName(v, t) : v.toString(), W = T(v) ? "/" : u("/", q(v)), H = this.shouldHavePrefix(t) ? u(t, W) : W, B = this.applyBaseUrl(t, H), b = typeof B == "string" ? B : B.path ?? H, w = {
147
- name: x,
148
- path: b,
149
- fullPath: b,
150
- params: { ...h.params, ...a.params },
151
- query: { ...h.query, ...a.query },
152
- hash: a.hash ?? h.hash
190
+ const P = e ? this.detectLocaleFromName(e.name) : this.detectLocaleFromName(r.name), i = P ? this.getBaseRouteName(r, P) : r.name ?? null;
191
+ if (!i) return s;
192
+ const p = this.shouldHavePrefix(t) ? this.buildLocalizedName(i, t) : i.toString(), S = I(i) ? "/" : m("/", T(i)), N = this.shouldHavePrefix(t) ? m(t, S) : S, H = this.applyBaseUrl(t, N), q = typeof H == "string" ? H : H.path ?? N, Q = {
193
+ name: p,
194
+ path: q,
195
+ fullPath: q,
196
+ params: { ...r.params, ...s.params },
197
+ query: { ...r.query, ...s.query },
198
+ hash: s.hash ?? r.hash
153
199
  };
154
- return this.preserveQueryAndHash(this.applyBaseUrl(t, w), a);
200
+ return this.preserveQueryAndHash(this.applyBaseUrl(t, Q), s);
155
201
  }
156
- getCanonicalPath(t, s) {
157
- const e = this.getCustomPathSegment(t, s);
202
+ getCanonicalPath(t, a) {
203
+ const e = this.getCustomPathSegment(t, a);
158
204
  if (!e) return null;
159
- const n = e.startsWith("/") ? e : `/${e}`;
160
- return this.shouldHavePrefix(s) ? k(`/${s}${n}`) : k(n);
205
+ const h = e.startsWith("/") ? e : `/${e}`;
206
+ return this.shouldHavePrefix(a) ? b(`/${a}${h}`) : b(h);
161
207
  }
162
208
  resolveLocaleFromPath(t) {
163
- const { localeFromPath: s } = this.getPathWithoutLocale(t);
164
- return s || this.ctx.defaultLocale;
165
- }
166
- getRedirect(t, s) {
167
- const { pathWithoutLocale: e, localeFromPath: n } = this.getPathWithoutLocale(t), a = this.shouldHavePrefix(s), h = this.ctx.globalLocaleRoutes;
168
- if (h && n !== null) {
169
- const x = e === "/" ? "/" : $(e);
170
- if (h[e] === !1 || h[x] === !1)
171
- return z(e);
209
+ const { localeFromPath: a } = this.getPathWithoutLocale(t);
210
+ return a || this.ctx.defaultLocale;
211
+ }
212
+ getRedirect(t, a) {
213
+ const { pathWithoutLocale: e, localeFromPath: h } = this.getPathWithoutLocale(t), s = this.shouldHavePrefix(a), r = this.ctx.globalLocaleRoutes;
214
+ if (r && h !== null) {
215
+ const p = e === "/" ? "/" : z(e);
216
+ if (r[e] === !1 || r[p] === !1)
217
+ return k(e);
172
218
  }
173
- if (n !== null) {
174
- if (n === this.ctx.defaultLocale)
175
- return z(e);
176
- if (n === s) {
177
- const x = this.buildPathWithPrefix(e, s), W = F(t);
178
- return Q(W, x) ? null : x;
219
+ if (h !== null) {
220
+ if (h === this.ctx.defaultLocale)
221
+ return k(e);
222
+ if (h === a) {
223
+ const p = this.buildPathWithPrefix(e, a), S = g(t);
224
+ return U(S, p) ? null : p;
179
225
  }
180
- return this.buildPathWithPrefix(e, s);
226
+ return this.buildPathWithPrefix(e, a);
181
227
  }
182
- if (a)
183
- return this.buildPathWithPrefix(e, s);
184
- const c = this.resolvePathForLocale(e, s), p = c.startsWith("/") ? c : `/${c}`, v = F(t);
185
- return Q(v, p) ? null : p;
228
+ if (s)
229
+ return this.buildPathWithPrefix(e, a);
230
+ const o = this.resolvePathForLocale(e, a), P = o.startsWith("/") ? o : `/${o}`, i = g(t);
231
+ return U(i, P) ? null : P;
232
+ }
233
+ shouldReturn404(t) {
234
+ const { pathWithoutLocale: a, localeFromPath: e } = this.getPathWithoutLocale(t);
235
+ return e === null ? null : e === this.ctx.defaultLocale && a === "/" ? "Default locale should not have prefix" : super.shouldReturn404(t);
186
236
  }
187
237
  /** True if gr[key] is a locale rules object (Record<locale, path>). */
188
238
  isLocaleRules(t) {
189
- const s = this.ctx.globalLocaleRoutes;
190
- if (!s || !t) return !1;
191
- const e = s[t];
239
+ const a = this.ctx.globalLocaleRoutes;
240
+ if (!a || !t) return !1;
241
+ const e = a[t];
192
242
  return typeof e == "object" && e !== null && !Array.isArray(e);
193
243
  }
194
244
  /**
@@ -197,34 +247,34 @@ class E extends I {
197
247
  */
198
248
  getNestedRouteInfo(t) {
199
249
  if (!this.ctx.globalLocaleRoutes) return null;
200
- const e = R(t), n = j(t);
250
+ const e = F(t), h = j(t);
201
251
  if (e.includes("/") && this.isLocaleRules(e))
202
- return { parentKey: g(e), keyWithSlash: e };
203
- if (n.includes("/") && this.isLocaleRules(n))
204
- return { parentKey: g(n), keyWithSlash: n };
205
- const a = g(e);
206
- if (e.includes("/") && a && this.isLocaleRules(a))
207
- return { parentKey: a, keyWithSlash: e };
208
- const h = g(n);
209
- return n.includes("/") && h && this.isLocaleRules(h) ? { parentKey: h, keyWithSlash: n } : null;
252
+ return { parentKey: B(e), keyWithSlash: e };
253
+ if (h.includes("/") && this.isLocaleRules(h))
254
+ return { parentKey: B(h), keyWithSlash: h };
255
+ const s = B(e);
256
+ if (e.includes("/") && s && this.isLocaleRules(s))
257
+ return { parentKey: s, keyWithSlash: e };
258
+ const r = B(h);
259
+ return h.includes("/") && r && this.isLocaleRules(r) ? { parentKey: r, keyWithSlash: h } : null;
210
260
  }
211
261
  /** Parent path for target locale from gr or currentRoute. */
212
- getParentPathForTarget(t, s, e, n) {
213
- const a = this.ctx.globalLocaleRoutes, h = t && a?.[t] && typeof a[t] == "object" && !Array.isArray(a[t]) ? a[t] : null;
214
- let c = h?.[e] ? S(h[e]) : "";
215
- if (!c && n?.path) {
216
- const p = F(n.path), { pathWithoutLocale: v } = this.getPathWithoutLocale(p);
217
- c = S(v);
262
+ getParentPathForTarget(t, a, e, h) {
263
+ const s = this.ctx.globalLocaleRoutes, r = t && s?.[t] && typeof s[t] == "object" && !Array.isArray(s[t]) ? s[t] : null;
264
+ let o = r?.[e] ? R(r[e]) : "";
265
+ if (!o && h?.path) {
266
+ const P = g(h.path), { pathWithoutLocale: i } = this.getPathWithoutLocale(P);
267
+ o = R(i);
218
268
  }
219
- if (!c) {
220
- const p = O(s).slice(0, -1);
221
- c = p.length ? u("/", ...p) : "";
269
+ if (!o) {
270
+ const P = D(a).slice(0, -1);
271
+ o = P.length ? m("/", ...P) : "";
222
272
  }
223
- return c;
273
+ return o;
224
274
  }
225
- buildPathWithPrefix(t, s) {
226
- const e = this.resolvePathForLocale(t, s);
227
- return e === "/" || e === "" ? `/${s}` : u(`/${s}`, e);
275
+ buildPathWithPrefix(t, a) {
276
+ const e = this.resolvePathForLocale(t, a);
277
+ return e === "/" || e === "" ? `/${a}` : m(`/${a}`, e);
228
278
  }
229
279
  /**
230
280
  * Simple locale detector based on route name suffix.
@@ -232,14 +282,35 @@ class E extends I {
232
282
  */
233
283
  detectLocaleFromName(t) {
234
284
  if (!t) return null;
235
- for (const s of this.ctx.locales)
236
- if (t.endsWith(`-${s.code}`))
237
- return s.code;
285
+ for (const a of this.ctx.locales)
286
+ if (t.endsWith(`-${a.code}`))
287
+ return a.code;
238
288
  return null;
239
289
  }
290
+ /**
291
+ * Formats path for router.resolve.
292
+ * prefix_except_default: add prefix only for non-default locale.
293
+ */
294
+ formatPathForResolve(t, a, e) {
295
+ return e !== this.ctx.defaultLocale ? `/${a}${t}` : t;
296
+ }
297
+ /**
298
+ * prefix_except_default: redirect based on preferred locale.
299
+ * Uses shouldHavePrefix to determine if locale needs prefix.
300
+ * Also handles custom paths from globalLocaleRoutes.
301
+ */
302
+ getClientRedirect(t, a) {
303
+ const { pathWithoutLocale: e, localeFromPath: h } = this.getPathWithoutLocale(t), s = this.ctx.globalLocaleRoutes, r = e === "/" ? "/" : z(e);
304
+ if (s && (s[e] === !1 || s[r] === !1) || h !== null) return null;
305
+ const o = this.resolvePathForLocale(e, a), P = this.shouldHavePrefix(a);
306
+ let i;
307
+ P ? i = b(`/${a}${o.startsWith("/") ? o : `/${o}`}`) : i = o.startsWith("/") ? o : `/${o}`, i !== "/" && i.endsWith("/") && (i = i.slice(0, -1));
308
+ const p = g(t);
309
+ return U(p, i) ? null : i;
310
+ }
240
311
  }
241
312
  export {
242
- E as PrefixExceptDefaultPathStrategy,
243
- E as Strategy
313
+ L as PrefixExceptDefaultPathStrategy,
314
+ L as Strategy
244
315
  };
245
316
  //# sourceMappingURL=prefix-except-default-strategy.mjs.map