@tanstack/router-core 1.128.3 → 1.128.6
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/cjs/path.cjs +242 -228
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/path.d.cts +11 -6
- package/dist/cjs/router.cjs +58 -47
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/esm/path.d.ts +11 -6
- package/dist/esm/path.js +242 -228
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/router.js +59 -48
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/path.ts +315 -296
- package/src/router.ts +79 -59
package/dist/cjs/path.cjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const utils = require("./utils.cjs");
|
|
4
|
+
const SEGMENT_TYPE_PATHNAME = 0;
|
|
5
|
+
const SEGMENT_TYPE_PARAM = 1;
|
|
6
|
+
const SEGMENT_TYPE_WILDCARD = 2;
|
|
7
|
+
const SEGMENT_TYPE_OPTIONAL_PARAM = 3;
|
|
4
8
|
function joinPaths(paths) {
|
|
5
9
|
return cleanPath(
|
|
6
10
|
paths.filter((val) => {
|
|
@@ -29,6 +33,44 @@ function removeTrailingSlash(value, basepath) {
|
|
|
29
33
|
function exactPathTest(pathName1, pathName2, basepath) {
|
|
30
34
|
return removeTrailingSlash(pathName1, basepath) === removeTrailingSlash(pathName2, basepath);
|
|
31
35
|
}
|
|
36
|
+
function segmentToString(segment) {
|
|
37
|
+
const { type, value } = segment;
|
|
38
|
+
if (type === SEGMENT_TYPE_PATHNAME) {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
const { prefixSegment, suffixSegment } = segment;
|
|
42
|
+
if (type === SEGMENT_TYPE_PARAM) {
|
|
43
|
+
const param = value.substring(1);
|
|
44
|
+
if (prefixSegment && suffixSegment) {
|
|
45
|
+
return `${prefixSegment}{$${param}}${suffixSegment}`;
|
|
46
|
+
} else if (prefixSegment) {
|
|
47
|
+
return `${prefixSegment}{$${param}}`;
|
|
48
|
+
} else if (suffixSegment) {
|
|
49
|
+
return `{$${param}}${suffixSegment}`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (type === SEGMENT_TYPE_OPTIONAL_PARAM) {
|
|
53
|
+
const param = value.substring(1);
|
|
54
|
+
if (prefixSegment && suffixSegment) {
|
|
55
|
+
return `${prefixSegment}{-$${param}}${suffixSegment}`;
|
|
56
|
+
} else if (prefixSegment) {
|
|
57
|
+
return `${prefixSegment}{-$${param}}`;
|
|
58
|
+
} else if (suffixSegment) {
|
|
59
|
+
return `{-$${param}}${suffixSegment}`;
|
|
60
|
+
}
|
|
61
|
+
return `{-$${param}}`;
|
|
62
|
+
}
|
|
63
|
+
if (type === SEGMENT_TYPE_WILDCARD) {
|
|
64
|
+
if (prefixSegment && suffixSegment) {
|
|
65
|
+
return `${prefixSegment}{$}${suffixSegment}`;
|
|
66
|
+
} else if (prefixSegment) {
|
|
67
|
+
return `${prefixSegment}{$}`;
|
|
68
|
+
} else if (suffixSegment) {
|
|
69
|
+
return `{$}${suffixSegment}`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
32
74
|
function resolvePath({
|
|
33
75
|
basepath,
|
|
34
76
|
base,
|
|
@@ -36,72 +78,42 @@ function resolvePath({
|
|
|
36
78
|
trailingSlash = "never",
|
|
37
79
|
caseSensitive
|
|
38
80
|
}) {
|
|
39
|
-
var _a
|
|
81
|
+
var _a;
|
|
40
82
|
base = removeBasepath(basepath, base, caseSensitive);
|
|
41
83
|
to = removeBasepath(basepath, to, caseSensitive);
|
|
42
|
-
let baseSegments = parsePathname(base);
|
|
84
|
+
let baseSegments = parsePathname(base).slice();
|
|
43
85
|
const toSegments = parsePathname(to);
|
|
44
86
|
if (baseSegments.length > 1 && ((_a = utils.last(baseSegments)) == null ? void 0 : _a.value) === "/") {
|
|
45
87
|
baseSegments.pop();
|
|
46
88
|
}
|
|
47
|
-
|
|
48
|
-
|
|
89
|
+
for (let index = 0, length = toSegments.length; index < length; index++) {
|
|
90
|
+
const toSegment = toSegments[index];
|
|
91
|
+
const value = toSegment.value;
|
|
92
|
+
if (value === "/") {
|
|
49
93
|
if (!index) {
|
|
50
94
|
baseSegments = [toSegment];
|
|
51
|
-
} else if (index ===
|
|
95
|
+
} else if (index === length - 1) {
|
|
52
96
|
baseSegments.push(toSegment);
|
|
53
97
|
} else ;
|
|
54
|
-
} else if (
|
|
98
|
+
} else if (value === "..") {
|
|
55
99
|
baseSegments.pop();
|
|
56
|
-
} else if (
|
|
100
|
+
} else if (value === ".") ;
|
|
57
101
|
else {
|
|
58
102
|
baseSegments.push(toSegment);
|
|
59
103
|
}
|
|
60
|
-
}
|
|
104
|
+
}
|
|
61
105
|
if (baseSegments.length > 1) {
|
|
62
|
-
if (
|
|
106
|
+
if (utils.last(baseSegments).value === "/") {
|
|
63
107
|
if (trailingSlash === "never") {
|
|
64
108
|
baseSegments.pop();
|
|
65
109
|
}
|
|
66
110
|
} else if (trailingSlash === "always") {
|
|
67
|
-
baseSegments.push({ type:
|
|
111
|
+
baseSegments.push({ type: SEGMENT_TYPE_PATHNAME, value: "/" });
|
|
68
112
|
}
|
|
69
113
|
}
|
|
70
|
-
const segmentValues = baseSegments.map(
|
|
71
|
-
if (segment.type === "param") {
|
|
72
|
-
const param = segment.value.substring(1);
|
|
73
|
-
if (segment.prefixSegment && segment.suffixSegment) {
|
|
74
|
-
return `${segment.prefixSegment}{$${param}}${segment.suffixSegment}`;
|
|
75
|
-
} else if (segment.prefixSegment) {
|
|
76
|
-
return `${segment.prefixSegment}{$${param}}`;
|
|
77
|
-
} else if (segment.suffixSegment) {
|
|
78
|
-
return `{$${param}}${segment.suffixSegment}`;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (segment.type === "optional-param") {
|
|
82
|
-
const param = segment.value.substring(1);
|
|
83
|
-
if (segment.prefixSegment && segment.suffixSegment) {
|
|
84
|
-
return `${segment.prefixSegment}{-$${param}}${segment.suffixSegment}`;
|
|
85
|
-
} else if (segment.prefixSegment) {
|
|
86
|
-
return `${segment.prefixSegment}{-$${param}}`;
|
|
87
|
-
} else if (segment.suffixSegment) {
|
|
88
|
-
return `{-$${param}}${segment.suffixSegment}`;
|
|
89
|
-
}
|
|
90
|
-
return `{-$${param}}`;
|
|
91
|
-
}
|
|
92
|
-
if (segment.type === "wildcard") {
|
|
93
|
-
if (segment.prefixSegment && segment.suffixSegment) {
|
|
94
|
-
return `${segment.prefixSegment}{$}${segment.suffixSegment}`;
|
|
95
|
-
} else if (segment.prefixSegment) {
|
|
96
|
-
return `${segment.prefixSegment}{$}`;
|
|
97
|
-
} else if (segment.suffixSegment) {
|
|
98
|
-
return `{$}${segment.suffixSegment}`;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return segment.value;
|
|
102
|
-
});
|
|
114
|
+
const segmentValues = baseSegments.map(segmentToString);
|
|
103
115
|
const joined = joinPaths([basepath, ...segmentValues]);
|
|
104
|
-
return
|
|
116
|
+
return joined;
|
|
105
117
|
}
|
|
106
118
|
const PARAM_RE = /^\$.{1,}$/;
|
|
107
119
|
const PARAM_W_CURLY_BRACES_RE = /^(.*?)\{(\$[a-zA-Z_$][a-zA-Z0-9_$]*)\}(.*)$/;
|
|
@@ -117,7 +129,7 @@ function parsePathname(pathname) {
|
|
|
117
129
|
if (pathname.slice(0, 1) === "/") {
|
|
118
130
|
pathname = pathname.substring(1);
|
|
119
131
|
segments.push({
|
|
120
|
-
type:
|
|
132
|
+
type: SEGMENT_TYPE_PATHNAME,
|
|
121
133
|
value: "/"
|
|
122
134
|
});
|
|
123
135
|
}
|
|
@@ -132,7 +144,7 @@ function parsePathname(pathname) {
|
|
|
132
144
|
const prefix = wildcardBracesMatch[1];
|
|
133
145
|
const suffix = wildcardBracesMatch[2];
|
|
134
146
|
return {
|
|
135
|
-
type:
|
|
147
|
+
type: SEGMENT_TYPE_WILDCARD,
|
|
136
148
|
value: "$",
|
|
137
149
|
prefixSegment: prefix || void 0,
|
|
138
150
|
suffixSegment: suffix || void 0
|
|
@@ -146,7 +158,7 @@ function parsePathname(pathname) {
|
|
|
146
158
|
const paramName = optionalParamBracesMatch[2];
|
|
147
159
|
const suffix = optionalParamBracesMatch[3];
|
|
148
160
|
return {
|
|
149
|
-
type:
|
|
161
|
+
type: SEGMENT_TYPE_OPTIONAL_PARAM,
|
|
150
162
|
value: paramName,
|
|
151
163
|
// Now just $paramName (no prefix)
|
|
152
164
|
prefixSegment: prefix || void 0,
|
|
@@ -159,7 +171,7 @@ function parsePathname(pathname) {
|
|
|
159
171
|
const paramName = paramBracesMatch[2];
|
|
160
172
|
const suffix = paramBracesMatch[3];
|
|
161
173
|
return {
|
|
162
|
-
type:
|
|
174
|
+
type: SEGMENT_TYPE_PARAM,
|
|
163
175
|
value: "" + paramName,
|
|
164
176
|
prefixSegment: prefix || void 0,
|
|
165
177
|
suffixSegment: suffix || void 0
|
|
@@ -168,7 +180,7 @@ function parsePathname(pathname) {
|
|
|
168
180
|
if (PARAM_RE.test(part)) {
|
|
169
181
|
const paramName = part.substring(1);
|
|
170
182
|
return {
|
|
171
|
-
type:
|
|
183
|
+
type: SEGMENT_TYPE_PARAM,
|
|
172
184
|
value: "$" + paramName,
|
|
173
185
|
prefixSegment: void 0,
|
|
174
186
|
suffixSegment: void 0
|
|
@@ -176,14 +188,14 @@ function parsePathname(pathname) {
|
|
|
176
188
|
}
|
|
177
189
|
if (WILDCARD_RE.test(part)) {
|
|
178
190
|
return {
|
|
179
|
-
type:
|
|
191
|
+
type: SEGMENT_TYPE_WILDCARD,
|
|
180
192
|
value: "$",
|
|
181
193
|
prefixSegment: void 0,
|
|
182
194
|
suffixSegment: void 0
|
|
183
195
|
};
|
|
184
196
|
}
|
|
185
197
|
return {
|
|
186
|
-
type:
|
|
198
|
+
type: SEGMENT_TYPE_PATHNAME,
|
|
187
199
|
value: part.includes("%25") ? part.split("%25").map((segment) => decodeURI(segment)).join("%25") : decodeURI(part)
|
|
188
200
|
};
|
|
189
201
|
})
|
|
@@ -191,7 +203,7 @@ function parsePathname(pathname) {
|
|
|
191
203
|
if (pathname.slice(-1) === "/") {
|
|
192
204
|
pathname = pathname.substring(1);
|
|
193
205
|
segments.push({
|
|
194
|
-
type:
|
|
206
|
+
type: SEGMENT_TYPE_PATHNAME,
|
|
195
207
|
value: "/"
|
|
196
208
|
});
|
|
197
209
|
}
|
|
@@ -208,7 +220,7 @@ function interpolatePath({
|
|
|
208
220
|
function encodeParam(key) {
|
|
209
221
|
const value = params[key];
|
|
210
222
|
const isValueString = typeof value === "string";
|
|
211
|
-
if (
|
|
223
|
+
if (key === "*" || key === "_splat") {
|
|
212
224
|
return isValueString ? encodeURI(value) : value;
|
|
213
225
|
} else {
|
|
214
226
|
return isValueString ? encodePathParam(value, decodeCharMap) : value;
|
|
@@ -218,7 +230,10 @@ function interpolatePath({
|
|
|
218
230
|
const usedParams = {};
|
|
219
231
|
const interpolatedPath = joinPaths(
|
|
220
232
|
interpolatedPathSegments.map((segment) => {
|
|
221
|
-
if (segment.type ===
|
|
233
|
+
if (segment.type === SEGMENT_TYPE_PATHNAME) {
|
|
234
|
+
return segment.value;
|
|
235
|
+
}
|
|
236
|
+
if (segment.type === SEGMENT_TYPE_WILDCARD) {
|
|
222
237
|
usedParams._splat = params._splat;
|
|
223
238
|
const segmentPrefix = segment.prefixSegment || "";
|
|
224
239
|
const segmentSuffix = segment.suffixSegment || "";
|
|
@@ -238,7 +253,7 @@ function interpolatePath({
|
|
|
238
253
|
}
|
|
239
254
|
return `${segmentPrefix}${value}${segmentSuffix}`;
|
|
240
255
|
}
|
|
241
|
-
if (segment.type ===
|
|
256
|
+
if (segment.type === SEGMENT_TYPE_PARAM) {
|
|
242
257
|
const key = segment.value.substring(1);
|
|
243
258
|
if (!isMissingParams && !(key in params)) {
|
|
244
259
|
isMissingParams = true;
|
|
@@ -252,11 +267,14 @@ function interpolatePath({
|
|
|
252
267
|
}
|
|
253
268
|
return `${segmentPrefix}${encodeParam(key) ?? "undefined"}${segmentSuffix}`;
|
|
254
269
|
}
|
|
255
|
-
if (segment.type ===
|
|
270
|
+
if (segment.type === SEGMENT_TYPE_OPTIONAL_PARAM) {
|
|
256
271
|
const key = segment.value.substring(1);
|
|
257
272
|
const segmentPrefix = segment.prefixSegment || "";
|
|
258
273
|
const segmentSuffix = segment.suffixSegment || "";
|
|
259
274
|
if (!(key in params) || params[key] == null) {
|
|
275
|
+
if (leaveWildcards) {
|
|
276
|
+
return `${segmentPrefix}${key}${segmentSuffix}`;
|
|
277
|
+
}
|
|
260
278
|
if (segmentPrefix || segmentSuffix) {
|
|
261
279
|
return `${segmentPrefix}${segmentSuffix}`;
|
|
262
280
|
}
|
|
@@ -319,120 +337,153 @@ function removeBasepath(basepath, pathname, caseSensitive = false) {
|
|
|
319
337
|
return pathname;
|
|
320
338
|
}
|
|
321
339
|
}
|
|
322
|
-
function matchByPath(basepath, from,
|
|
340
|
+
function matchByPath(basepath, from, {
|
|
341
|
+
to,
|
|
342
|
+
fuzzy,
|
|
343
|
+
caseSensitive
|
|
344
|
+
}) {
|
|
323
345
|
if (basepath !== "/" && !from.startsWith(basepath)) {
|
|
324
346
|
return void 0;
|
|
325
347
|
}
|
|
326
|
-
from = removeBasepath(basepath, from,
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
matchLocation.caseSensitive
|
|
331
|
-
);
|
|
332
|
-
const baseSegments = parsePathname(from);
|
|
333
|
-
const routeSegments = parsePathname(to);
|
|
334
|
-
if (!from.startsWith("/")) {
|
|
335
|
-
baseSegments.unshift({
|
|
336
|
-
type: "pathname",
|
|
337
|
-
value: "/"
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
if (!to.startsWith("/")) {
|
|
341
|
-
routeSegments.unshift({
|
|
342
|
-
type: "pathname",
|
|
343
|
-
value: "/"
|
|
344
|
-
});
|
|
345
|
-
}
|
|
348
|
+
from = removeBasepath(basepath, from, caseSensitive);
|
|
349
|
+
to = removeBasepath(basepath, `${to ?? "$"}`, caseSensitive);
|
|
350
|
+
const baseSegments = parsePathname(from.startsWith("/") ? from : `/${from}`);
|
|
351
|
+
const routeSegments = parsePathname(to.startsWith("/") ? to : `/${to}`);
|
|
346
352
|
const params = {};
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
);
|
|
378
|
-
if (prefix && rejoinedSplat.startsWith(prefix)) {
|
|
379
|
-
rejoinedSplat = rejoinedSplat.slice(prefix.length);
|
|
353
|
+
const result = isMatch(
|
|
354
|
+
baseSegments,
|
|
355
|
+
routeSegments,
|
|
356
|
+
params,
|
|
357
|
+
fuzzy,
|
|
358
|
+
caseSensitive
|
|
359
|
+
);
|
|
360
|
+
return result ? params : void 0;
|
|
361
|
+
}
|
|
362
|
+
function isMatch(baseSegments, routeSegments, params, fuzzy, caseSensitive) {
|
|
363
|
+
var _a, _b;
|
|
364
|
+
let baseIndex = 0;
|
|
365
|
+
let routeIndex = 0;
|
|
366
|
+
while (baseIndex < baseSegments.length || routeIndex < routeSegments.length) {
|
|
367
|
+
const baseSegment = baseSegments[baseIndex];
|
|
368
|
+
const routeSegment = routeSegments[routeIndex];
|
|
369
|
+
const isLastBaseSegment = baseIndex >= baseSegments.length - 1;
|
|
370
|
+
const isLastRouteSegment = routeIndex >= routeSegments.length - 1;
|
|
371
|
+
if (routeSegment) {
|
|
372
|
+
if (routeSegment.type === SEGMENT_TYPE_WILDCARD) {
|
|
373
|
+
const remainingBaseSegments = baseSegments.slice(baseIndex);
|
|
374
|
+
let _splat;
|
|
375
|
+
if (routeSegment.prefixSegment || routeSegment.suffixSegment) {
|
|
376
|
+
if (!baseSegment) return false;
|
|
377
|
+
const prefix = routeSegment.prefixSegment || "";
|
|
378
|
+
const suffix = routeSegment.suffixSegment || "";
|
|
379
|
+
const baseValue = baseSegment.value;
|
|
380
|
+
if ("prefixSegment" in routeSegment) {
|
|
381
|
+
if (!baseValue.startsWith(prefix)) {
|
|
382
|
+
return false;
|
|
380
383
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
);
|
|
384
|
+
}
|
|
385
|
+
if ("suffixSegment" in routeSegment) {
|
|
386
|
+
if (!((_a = baseSegments[baseSegments.length - 1]) == null ? void 0 : _a.value.endsWith(suffix))) {
|
|
387
|
+
return false;
|
|
386
388
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
389
|
+
}
|
|
390
|
+
let rejoinedSplat = decodeURI(
|
|
391
|
+
joinPaths(remainingBaseSegments.map((d) => d.value))
|
|
392
|
+
);
|
|
393
|
+
if (prefix && rejoinedSplat.startsWith(prefix)) {
|
|
394
|
+
rejoinedSplat = rejoinedSplat.slice(prefix.length);
|
|
395
|
+
}
|
|
396
|
+
if (suffix && rejoinedSplat.endsWith(suffix)) {
|
|
397
|
+
rejoinedSplat = rejoinedSplat.slice(
|
|
398
|
+
0,
|
|
399
|
+
rejoinedSplat.length - suffix.length
|
|
391
400
|
);
|
|
392
401
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
402
|
+
_splat = rejoinedSplat;
|
|
403
|
+
} else {
|
|
404
|
+
_splat = decodeURI(
|
|
405
|
+
joinPaths(remainingBaseSegments.map((d) => d.value))
|
|
406
|
+
);
|
|
396
407
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
+
params["*"] = _splat;
|
|
409
|
+
params["_splat"] = _splat;
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
if (routeSegment.type === SEGMENT_TYPE_PATHNAME) {
|
|
413
|
+
if (routeSegment.value === "/" && !(baseSegment == null ? void 0 : baseSegment.value)) {
|
|
414
|
+
routeIndex++;
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
if (baseSegment) {
|
|
418
|
+
if (caseSensitive) {
|
|
419
|
+
if (routeSegment.value !== baseSegment.value) {
|
|
408
420
|
return false;
|
|
409
421
|
}
|
|
410
|
-
|
|
411
|
-
routeIndex++;
|
|
412
|
-
continue;
|
|
413
|
-
} else {
|
|
422
|
+
} else if (routeSegment.value.toLowerCase() !== baseSegment.value.toLowerCase()) {
|
|
414
423
|
return false;
|
|
415
424
|
}
|
|
425
|
+
baseIndex++;
|
|
426
|
+
routeIndex++;
|
|
427
|
+
continue;
|
|
428
|
+
} else {
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (routeSegment.type === SEGMENT_TYPE_PARAM) {
|
|
433
|
+
if (!baseSegment) {
|
|
434
|
+
return false;
|
|
416
435
|
}
|
|
417
|
-
if (
|
|
418
|
-
|
|
436
|
+
if (baseSegment.value === "/") {
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
let _paramValue = "";
|
|
440
|
+
let matched = false;
|
|
441
|
+
if (routeSegment.prefixSegment || routeSegment.suffixSegment) {
|
|
442
|
+
const prefix = routeSegment.prefixSegment || "";
|
|
443
|
+
const suffix = routeSegment.suffixSegment || "";
|
|
444
|
+
const baseValue = baseSegment.value;
|
|
445
|
+
if (prefix && !baseValue.startsWith(prefix)) {
|
|
419
446
|
return false;
|
|
420
447
|
}
|
|
421
|
-
if (
|
|
448
|
+
if (suffix && !baseValue.endsWith(suffix)) {
|
|
422
449
|
return false;
|
|
423
450
|
}
|
|
424
|
-
let
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
451
|
+
let paramValue = baseValue;
|
|
452
|
+
if (prefix && paramValue.startsWith(prefix)) {
|
|
453
|
+
paramValue = paramValue.slice(prefix.length);
|
|
454
|
+
}
|
|
455
|
+
if (suffix && paramValue.endsWith(suffix)) {
|
|
456
|
+
paramValue = paramValue.slice(0, paramValue.length - suffix.length);
|
|
457
|
+
}
|
|
458
|
+
_paramValue = decodeURIComponent(paramValue);
|
|
459
|
+
matched = true;
|
|
460
|
+
} else {
|
|
461
|
+
_paramValue = decodeURIComponent(baseSegment.value);
|
|
462
|
+
matched = true;
|
|
463
|
+
}
|
|
464
|
+
if (matched) {
|
|
465
|
+
params[routeSegment.value.substring(1)] = _paramValue;
|
|
466
|
+
baseIndex++;
|
|
467
|
+
}
|
|
468
|
+
routeIndex++;
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
if (routeSegment.type === SEGMENT_TYPE_OPTIONAL_PARAM) {
|
|
472
|
+
if (!baseSegment) {
|
|
473
|
+
routeIndex++;
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
if (baseSegment.value === "/") {
|
|
477
|
+
routeIndex++;
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
let _paramValue = "";
|
|
481
|
+
let matched = false;
|
|
482
|
+
if (routeSegment.prefixSegment || routeSegment.suffixSegment) {
|
|
483
|
+
const prefix = routeSegment.prefixSegment || "";
|
|
484
|
+
const suffix = routeSegment.suffixSegment || "";
|
|
485
|
+
const baseValue = baseSegment.value;
|
|
486
|
+
if ((!prefix || baseValue.startsWith(prefix)) && (!suffix || baseValue.endsWith(suffix))) {
|
|
436
487
|
let paramValue = baseValue;
|
|
437
488
|
if (prefix && paramValue.startsWith(prefix)) {
|
|
438
489
|
paramValue = paramValue.slice(prefix.length);
|
|
@@ -445,94 +496,57 @@ function matchByPath(basepath, from, matchLocation) {
|
|
|
445
496
|
}
|
|
446
497
|
_paramValue = decodeURIComponent(paramValue);
|
|
447
498
|
matched = true;
|
|
448
|
-
} else {
|
|
449
|
-
_paramValue = decodeURIComponent(baseSegment.value);
|
|
450
|
-
matched = true;
|
|
451
|
-
}
|
|
452
|
-
if (matched) {
|
|
453
|
-
params[routeSegment.value.substring(1)] = _paramValue;
|
|
454
|
-
baseIndex++;
|
|
455
|
-
}
|
|
456
|
-
routeIndex++;
|
|
457
|
-
continue;
|
|
458
|
-
}
|
|
459
|
-
if (routeSegment.type === "optional-param") {
|
|
460
|
-
if (!baseSegment) {
|
|
461
|
-
routeIndex++;
|
|
462
|
-
continue;
|
|
463
499
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
const prefix = routeSegment.prefixSegment || "";
|
|
472
|
-
const suffix = routeSegment.suffixSegment || "";
|
|
473
|
-
const baseValue = baseSegment.value;
|
|
474
|
-
if ((!prefix || baseValue.startsWith(prefix)) && (!suffix || baseValue.endsWith(suffix))) {
|
|
475
|
-
let paramValue = baseValue;
|
|
476
|
-
if (prefix && paramValue.startsWith(prefix)) {
|
|
477
|
-
paramValue = paramValue.slice(prefix.length);
|
|
478
|
-
}
|
|
479
|
-
if (suffix && paramValue.endsWith(suffix)) {
|
|
480
|
-
paramValue = paramValue.slice(
|
|
481
|
-
0,
|
|
482
|
-
paramValue.length - suffix.length
|
|
483
|
-
);
|
|
484
|
-
}
|
|
485
|
-
_paramValue = decodeURIComponent(paramValue);
|
|
486
|
-
matched = true;
|
|
487
|
-
}
|
|
488
|
-
} else {
|
|
489
|
-
let shouldMatchOptional = true;
|
|
490
|
-
for (let lookAhead = routeIndex + 1; lookAhead < routeSegments.length; lookAhead++) {
|
|
491
|
-
const futureRouteSegment = routeSegments[lookAhead];
|
|
492
|
-
if ((futureRouteSegment == null ? void 0 : futureRouteSegment.type) === "pathname" && futureRouteSegment.value === baseSegment.value) {
|
|
493
|
-
shouldMatchOptional = false;
|
|
494
|
-
break;
|
|
495
|
-
}
|
|
496
|
-
if ((futureRouteSegment == null ? void 0 : futureRouteSegment.type) === "param" || (futureRouteSegment == null ? void 0 : futureRouteSegment.type) === "wildcard") {
|
|
497
|
-
break;
|
|
498
|
-
}
|
|
500
|
+
} else {
|
|
501
|
+
let shouldMatchOptional = true;
|
|
502
|
+
for (let lookAhead = routeIndex + 1; lookAhead < routeSegments.length; lookAhead++) {
|
|
503
|
+
const futureRouteSegment = routeSegments[lookAhead];
|
|
504
|
+
if ((futureRouteSegment == null ? void 0 : futureRouteSegment.type) === SEGMENT_TYPE_PATHNAME && futureRouteSegment.value === baseSegment.value) {
|
|
505
|
+
shouldMatchOptional = false;
|
|
506
|
+
break;
|
|
499
507
|
}
|
|
500
|
-
if (
|
|
501
|
-
|
|
502
|
-
matched = true;
|
|
508
|
+
if ((futureRouteSegment == null ? void 0 : futureRouteSegment.type) === SEGMENT_TYPE_PARAM || (futureRouteSegment == null ? void 0 : futureRouteSegment.type) === SEGMENT_TYPE_WILDCARD) {
|
|
509
|
+
break;
|
|
503
510
|
}
|
|
504
511
|
}
|
|
505
|
-
if (
|
|
506
|
-
|
|
507
|
-
|
|
512
|
+
if (shouldMatchOptional) {
|
|
513
|
+
_paramValue = decodeURIComponent(baseSegment.value);
|
|
514
|
+
matched = true;
|
|
508
515
|
}
|
|
509
|
-
routeIndex++;
|
|
510
|
-
continue;
|
|
511
516
|
}
|
|
517
|
+
if (matched) {
|
|
518
|
+
params[routeSegment.value.substring(1)] = _paramValue;
|
|
519
|
+
baseIndex++;
|
|
520
|
+
}
|
|
521
|
+
routeIndex++;
|
|
522
|
+
continue;
|
|
512
523
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
)
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
524
|
+
}
|
|
525
|
+
if (!isLastBaseSegment && isLastRouteSegment) {
|
|
526
|
+
params["**"] = joinPaths(
|
|
527
|
+
baseSegments.slice(baseIndex + 1).map((d) => d.value)
|
|
528
|
+
);
|
|
529
|
+
return !!fuzzy && (routeSegment == null ? void 0 : routeSegment.value) !== "/";
|
|
530
|
+
}
|
|
531
|
+
if (baseIndex < baseSegments.length && routeIndex >= routeSegments.length) {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
if (routeIndex < routeSegments.length && baseIndex >= baseSegments.length) {
|
|
535
|
+
for (let i = routeIndex; i < routeSegments.length; i++) {
|
|
536
|
+
if (((_b = routeSegments[i]) == null ? void 0 : _b.type) !== SEGMENT_TYPE_OPTIONAL_PARAM) {
|
|
537
|
+
return false;
|
|
527
538
|
}
|
|
528
|
-
break;
|
|
529
539
|
}
|
|
530
540
|
break;
|
|
531
541
|
}
|
|
532
|
-
|
|
533
|
-
}
|
|
534
|
-
return
|
|
542
|
+
break;
|
|
543
|
+
}
|
|
544
|
+
return true;
|
|
535
545
|
}
|
|
546
|
+
exports.SEGMENT_TYPE_OPTIONAL_PARAM = SEGMENT_TYPE_OPTIONAL_PARAM;
|
|
547
|
+
exports.SEGMENT_TYPE_PARAM = SEGMENT_TYPE_PARAM;
|
|
548
|
+
exports.SEGMENT_TYPE_PATHNAME = SEGMENT_TYPE_PATHNAME;
|
|
549
|
+
exports.SEGMENT_TYPE_WILDCARD = SEGMENT_TYPE_WILDCARD;
|
|
536
550
|
exports.cleanPath = cleanPath;
|
|
537
551
|
exports.exactPathTest = exactPathTest;
|
|
538
552
|
exports.interpolatePath = interpolatePath;
|