@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.
- package/README.md +75 -29
- package/dist/base-strategy-BHkH418r.cjs +2 -0
- package/dist/base-strategy-BHkH418r.cjs.map +1 -0
- package/dist/base-strategy-CSEFam3u.js +585 -0
- package/dist/base-strategy-CSEFam3u.js.map +1 -0
- package/dist/common-BaGdobUC.js +114 -0
- package/dist/common-BaGdobUC.js.map +1 -0
- package/dist/common-sNHyO9pg.cjs +2 -0
- package/dist/common-sNHyO9pg.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +63 -352
- package/dist/index.mjs +21 -34
- 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 +38 -262
- package/dist/no-prefix-strategy.mjs +17 -32
- 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 +36 -259
- package/dist/prefix-and-default-strategy.mjs +75 -125
- 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 +41 -269
- package/dist/prefix-except-default-strategy.mjs +228 -251
- 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 +36 -257
- package/dist/prefix-strategy.mjs +16 -53
- package/dist/prefix-strategy.mjs.map +1 -1
- package/dist/types.d.ts +23 -78
- package/package.json +6 -4
- package/dist/base-strategy-BNdOdpRE.cjs +0 -2
- package/dist/base-strategy-BNdOdpRE.cjs.map +0 -1
- package/dist/base-strategy-DmOQzfP1.js +0 -922
- package/dist/base-strategy-DmOQzfP1.js.map +0 -1
|
@@ -1,314 +1,291 @@
|
|
|
1
|
-
import { B as
|
|
2
|
-
class
|
|
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
|
|
9
|
-
return !(
|
|
5
|
+
const s = this.ctx.locales.find((a) => a.code === t);
|
|
6
|
+
return !(s?.baseUrl && s?.baseDefault);
|
|
10
7
|
}
|
|
11
|
-
buildLocalizedPath(t,
|
|
12
|
-
return this.shouldHavePrefix(
|
|
8
|
+
buildLocalizedPath(t, s, a) {
|
|
9
|
+
return this.shouldHavePrefix(s) ? o(s, P(t)) : P(t);
|
|
13
10
|
}
|
|
14
|
-
buildLocalizedRouteName(t,
|
|
15
|
-
return this.shouldHavePrefix(
|
|
11
|
+
buildLocalizedRouteName(t, s) {
|
|
12
|
+
return this.shouldHavePrefix(s) ? this.buildLocalizedName(t, s) : t;
|
|
16
13
|
}
|
|
17
|
-
switchLocaleRoute(t,
|
|
18
|
-
const
|
|
19
|
-
if (!
|
|
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 (
|
|
22
|
-
const
|
|
23
|
-
r =
|
|
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 =
|
|
23
|
+
r = i;
|
|
26
24
|
if (this.ctx.router.hasRoute(r)) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const
|
|
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:
|
|
32
|
-
path:
|
|
33
|
-
fullPath:
|
|
34
|
-
query:
|
|
35
|
-
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(
|
|
35
|
+
return this.applyBaseUrl(s, c);
|
|
38
36
|
}
|
|
39
|
-
const
|
|
40
|
-
return this.applyBaseUrl(
|
|
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,
|
|
43
|
-
if (
|
|
44
|
-
const
|
|
45
|
-
|
|
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:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
const u = this.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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 (
|
|
101
|
-
const l = this.
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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 (
|
|
119
|
-
const { pathWithoutLocale:
|
|
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 (
|
|
122
|
-
const
|
|
123
|
-
x =
|
|
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 =
|
|
161
|
+
x = u && u !== "/" ? u : null;
|
|
129
162
|
if (x) {
|
|
130
|
-
const
|
|
131
|
-
|
|
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 (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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:
|
|
170
|
-
params:
|
|
171
|
-
query:
|
|
172
|
-
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
|
|
180
|
+
return y(
|
|
176
181
|
this.applyBaseUrl(t, {
|
|
177
|
-
name:
|
|
182
|
+
name: s,
|
|
178
183
|
path: l.path,
|
|
179
184
|
fullPath: l.fullPath,
|
|
180
185
|
params: l.params,
|
|
181
|
-
query: l.query ??
|
|
182
|
-
hash: l.hash ??
|
|
186
|
+
query: l.query ?? a.query,
|
|
187
|
+
hash: l.hash ?? a.hash
|
|
183
188
|
}),
|
|
184
|
-
|
|
189
|
+
a
|
|
185
190
|
);
|
|
186
191
|
}
|
|
187
192
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
|
|
208
|
-
return a || this.ctx.defaultLocale;
|
|
208
|
+
return super.resolveLocaleFromPath(t) ?? this.ctx.defaultLocale;
|
|
209
209
|
}
|
|
210
|
-
getRedirect(t,
|
|
211
|
-
const { pathWithoutLocale:
|
|
212
|
-
if (
|
|
213
|
-
|
|
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
|
|
220
|
-
if (h ===
|
|
221
|
-
const
|
|
222
|
-
return U(
|
|
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
|
|
221
|
+
return d(this, a, s);
|
|
225
222
|
}
|
|
226
|
-
if (
|
|
227
|
-
return this
|
|
228
|
-
const
|
|
229
|
-
return U(
|
|
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:
|
|
233
|
-
return
|
|
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
|
|
238
|
-
if (!
|
|
239
|
-
const
|
|
240
|
-
return typeof
|
|
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
|
|
249
|
-
if (
|
|
250
|
-
return { parentKey:
|
|
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:
|
|
253
|
-
const
|
|
254
|
-
if (
|
|
255
|
-
return { parentKey:
|
|
256
|
-
const
|
|
257
|
-
return h.includes("/") &&
|
|
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
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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 (!
|
|
268
|
-
const
|
|
269
|
-
|
|
268
|
+
if (!r) {
|
|
269
|
+
const p = G(s).slice(0, -1);
|
|
270
|
+
r = p.length ? o("/", ...p) : "";
|
|
270
271
|
}
|
|
271
|
-
return
|
|
272
|
+
return r;
|
|
272
273
|
}
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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
|
-
|
|
312
|
-
|
|
288
|
+
J as PrefixExceptDefaultPathStrategy,
|
|
289
|
+
J as Strategy
|
|
313
290
|
};
|
|
314
291
|
//# sourceMappingURL=prefix-except-default-strategy.mjs.map
|