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