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