@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.
- package/dist/base-strategy-BuHeTv1K.cjs +2 -0
- package/dist/base-strategy-BuHeTv1K.cjs.map +1 -0
- package/dist/base-strategy-Cf39XK8k.js +926 -0
- 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.d.ts +134 -4
- package/dist/index.mjs +8 -8
- package/dist/index.mjs.map +1 -1
- package/dist/no-prefix-strategy.cjs +1 -1
- package/dist/no-prefix-strategy.cjs.map +1 -1
- package/dist/no-prefix-strategy.d.ts +100 -4
- package/dist/no-prefix-strategy.mjs +42 -22
- package/dist/no-prefix-strategy.mjs.map +1 -1
- package/dist/prefix-and-default-strategy.cjs +1 -1
- package/dist/prefix-and-default-strategy.cjs.map +1 -1
- package/dist/prefix-and-default-strategy.d.ts +97 -4
- package/dist/prefix-and-default-strategy.mjs +101 -84
- package/dist/prefix-and-default-strategy.mjs.map +1 -1
- package/dist/prefix-except-default-strategy.cjs +1 -1
- package/dist/prefix-except-default-strategy.cjs.map +1 -1
- package/dist/prefix-except-default-strategy.d.ts +98 -4
- package/dist/prefix-except-default-strategy.mjs +248 -177
- package/dist/prefix-except-default-strategy.mjs.map +1 -1
- package/dist/prefix-strategy.cjs +1 -1
- package/dist/prefix-strategy.cjs.map +1 -1
- package/dist/prefix-strategy.d.ts +97 -4
- package/dist/prefix-strategy.mjs +35 -14
- package/dist/prefix-strategy.mjs.map +1 -1
- package/dist/types.d.ts +46 -1
- package/package.json +2 -2
- package/dist/base-strategy-B5mBf3XX.cjs +0 -2
- package/dist/base-strategy-B5mBf3XX.cjs.map +0 -1
- package/dist/base-strategy-DVqe8ehd.js +0 -790
- package/dist/base-strategy-DVqe8ehd.js.map +0 -1
|
@@ -1,194 +1,244 @@
|
|
|
1
|
-
import { B as
|
|
2
|
-
class
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return this.shouldHavePrefix(
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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(
|
|
39
|
+
return this.applyBaseUrl(a, N);
|
|
30
40
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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:
|
|
41
|
-
if (
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
const
|
|
45
|
-
name:
|
|
46
|
-
path:
|
|
47
|
-
fullPath:
|
|
48
|
-
params:
|
|
49
|
-
},
|
|
50
|
-
if (
|
|
51
|
-
const
|
|
52
|
-
let
|
|
53
|
-
if (
|
|
54
|
-
const
|
|
55
|
-
|
|
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
|
-
|
|
68
|
+
d = R(n);
|
|
58
69
|
if (!this.shouldHavePrefix(t))
|
|
59
|
-
return this.preserveQueryAndHash(this.applyBaseUrl(t,
|
|
60
|
-
const
|
|
61
|
-
return this.preserveQueryAndHash(this.applyBaseUrl(t,
|
|
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
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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 (
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
80
|
-
return this.preserveQueryAndHash(this.applyBaseUrl(t,
|
|
81
|
-
const
|
|
82
|
-
if (
|
|
83
|
-
const
|
|
84
|
-
let
|
|
85
|
-
if (
|
|
86
|
-
const
|
|
87
|
-
|
|
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
|
-
|
|
114
|
+
n = R(u);
|
|
90
115
|
if (!this.shouldHavePrefix(t))
|
|
91
|
-
return this.preserveQueryAndHash(this.applyBaseUrl(t,
|
|
92
|
-
const
|
|
93
|
-
return this.preserveQueryAndHash(this.applyBaseUrl(t,
|
|
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 (
|
|
96
|
-
const { pathWithoutLocale:
|
|
97
|
-
let
|
|
98
|
-
if (
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
} else if (
|
|
102
|
-
const
|
|
103
|
-
|
|
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
|
-
|
|
106
|
-
if (
|
|
107
|
-
const
|
|
108
|
-
...
|
|
109
|
-
path:
|
|
110
|
-
fullPath:
|
|
111
|
-
params: { ...
|
|
112
|
-
query: { ...
|
|
113
|
-
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,
|
|
140
|
+
return this.preserveQueryAndHash(this.applyBaseUrl(t, w), s);
|
|
116
141
|
}
|
|
117
142
|
}
|
|
118
143
|
}
|
|
119
|
-
if (
|
|
120
|
-
const
|
|
121
|
-
name:
|
|
122
|
-
path:
|
|
123
|
-
fullPath:
|
|
124
|
-
params:
|
|
125
|
-
},
|
|
126
|
-
if (
|
|
127
|
-
const
|
|
128
|
-
let
|
|
129
|
-
if (
|
|
130
|
-
const
|
|
131
|
-
|
|
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
|
-
|
|
158
|
+
f = R(y);
|
|
134
159
|
if (!this.shouldHavePrefix(t))
|
|
135
|
-
return this.preserveQueryAndHash(this.applyBaseUrl(t,
|
|
136
|
-
const
|
|
137
|
-
return this.preserveQueryAndHash(this.applyBaseUrl(t,
|
|
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 (
|
|
141
|
-
|
|
142
|
-
|
|
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
|
|
145
|
-
if (!
|
|
146
|
-
const
|
|
147
|
-
name:
|
|
148
|
-
path:
|
|
149
|
-
fullPath:
|
|
150
|
-
params: { ...
|
|
151
|
-
query: { ...
|
|
152
|
-
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,
|
|
200
|
+
return this.preserveQueryAndHash(this.applyBaseUrl(t, Q), s);
|
|
155
201
|
}
|
|
156
|
-
getCanonicalPath(t,
|
|
157
|
-
const e = this.getCustomPathSegment(t,
|
|
202
|
+
getCanonicalPath(t, a) {
|
|
203
|
+
const e = this.getCustomPathSegment(t, a);
|
|
158
204
|
if (!e) return null;
|
|
159
|
-
const
|
|
160
|
-
return this.shouldHavePrefix(
|
|
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:
|
|
164
|
-
return
|
|
165
|
-
}
|
|
166
|
-
getRedirect(t,
|
|
167
|
-
const { pathWithoutLocale: e, localeFromPath:
|
|
168
|
-
if (
|
|
169
|
-
const
|
|
170
|
-
if (
|
|
171
|
-
return
|
|
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 (
|
|
174
|
-
if (
|
|
175
|
-
return
|
|
176
|
-
if (
|
|
177
|
-
const
|
|
178
|
-
return
|
|
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,
|
|
226
|
+
return this.buildPathWithPrefix(e, a);
|
|
181
227
|
}
|
|
182
|
-
if (
|
|
183
|
-
return this.buildPathWithPrefix(e,
|
|
184
|
-
const
|
|
185
|
-
return
|
|
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
|
|
190
|
-
if (!
|
|
191
|
-
const e =
|
|
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 =
|
|
250
|
+
const e = F(t), h = j(t);
|
|
201
251
|
if (e.includes("/") && this.isLocaleRules(e))
|
|
202
|
-
return { parentKey:
|
|
203
|
-
if (
|
|
204
|
-
return { parentKey:
|
|
205
|
-
const
|
|
206
|
-
if (e.includes("/") &&
|
|
207
|
-
return { parentKey:
|
|
208
|
-
const
|
|
209
|
-
return
|
|
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,
|
|
213
|
-
const
|
|
214
|
-
let
|
|
215
|
-
if (!
|
|
216
|
-
const
|
|
217
|
-
|
|
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 (!
|
|
220
|
-
const
|
|
221
|
-
|
|
269
|
+
if (!o) {
|
|
270
|
+
const P = D(a).slice(0, -1);
|
|
271
|
+
o = P.length ? m("/", ...P) : "";
|
|
222
272
|
}
|
|
223
|
-
return
|
|
273
|
+
return o;
|
|
224
274
|
}
|
|
225
|
-
buildPathWithPrefix(t,
|
|
226
|
-
const e = this.resolvePathForLocale(t,
|
|
227
|
-
return e === "/" || 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
|
|
236
|
-
if (t.endsWith(`-${
|
|
237
|
-
return
|
|
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
|
-
|
|
243
|
-
|
|
313
|
+
L as PrefixExceptDefaultPathStrategy,
|
|
314
|
+
L as Strategy
|
|
244
315
|
};
|
|
245
316
|
//# sourceMappingURL=prefix-except-default-strategy.mjs.map
|