@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/esm/path.d.ts
CHANGED
|
@@ -1,10 +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
|
+
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;
|
|
8
13
|
}
|
|
9
14
|
export declare function joinPaths(paths: Array<string | undefined>): string;
|
|
10
15
|
export declare function cleanPath(path: string): string;
|
|
@@ -38,7 +43,7 @@ export declare function resolvePath({ basepath, base, to, trailingSlash, caseSen
|
|
|
38
43
|
* - `/foo/[$]{$foo} - Dynamic route with a static prefix of `$`
|
|
39
44
|
* - `/foo/{$foo}[$]` - Dynamic route with a static suffix of `$`
|
|
40
45
|
*/
|
|
41
|
-
export declare function parsePathname(pathname?: string):
|
|
46
|
+
export declare function parsePathname(pathname?: string): ReadonlyArray<Segment>;
|
|
42
47
|
interface InterpolatePathOptions {
|
|
43
48
|
path?: string;
|
|
44
49
|
params: Record<string, unknown>;
|
|
@@ -54,5 +59,5 @@ type InterPolatePathResult = {
|
|
|
54
59
|
export declare function interpolatePath({ path, params, leaveWildcards, leaveParams, decodeCharMap, }: InterpolatePathOptions): InterPolatePathResult;
|
|
55
60
|
export declare function matchPathname(basepath: string, currentPathname: string, matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>): AnyPathParams | undefined;
|
|
56
61
|
export declare function removeBasepath(basepath: string, pathname: string, caseSensitive?: boolean): string;
|
|
57
|
-
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;
|
|
58
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,153 @@ 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
|
-
|
|
374
|
-
|
|
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;
|
|
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
|
+
const isLastBaseSegment = baseIndex >= baseSegments.length - 1;
|
|
368
|
+
const isLastRouteSegment = routeIndex >= routeSegments.length - 1;
|
|
369
|
+
if (routeSegment) {
|
|
370
|
+
if (routeSegment.type === SEGMENT_TYPE_WILDCARD) {
|
|
371
|
+
const remainingBaseSegments = baseSegments.slice(baseIndex);
|
|
372
|
+
let _splat;
|
|
373
|
+
if (routeSegment.prefixSegment || routeSegment.suffixSegment) {
|
|
374
|
+
if (!baseSegment) return false;
|
|
375
|
+
const prefix = routeSegment.prefixSegment || "";
|
|
376
|
+
const suffix = routeSegment.suffixSegment || "";
|
|
377
|
+
const baseValue = baseSegment.value;
|
|
378
|
+
if ("prefixSegment" in routeSegment) {
|
|
379
|
+
if (!baseValue.startsWith(prefix)) {
|
|
380
|
+
return false;
|
|
378
381
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
);
|
|
382
|
+
}
|
|
383
|
+
if ("suffixSegment" in routeSegment) {
|
|
384
|
+
if (!((_a = baseSegments[baseSegments.length - 1]) == null ? void 0 : _a.value.endsWith(suffix))) {
|
|
385
|
+
return false;
|
|
384
386
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
387
|
+
}
|
|
388
|
+
let rejoinedSplat = decodeURI(
|
|
389
|
+
joinPaths(remainingBaseSegments.map((d) => d.value))
|
|
390
|
+
);
|
|
391
|
+
if (prefix && rejoinedSplat.startsWith(prefix)) {
|
|
392
|
+
rejoinedSplat = rejoinedSplat.slice(prefix.length);
|
|
393
|
+
}
|
|
394
|
+
if (suffix && rejoinedSplat.endsWith(suffix)) {
|
|
395
|
+
rejoinedSplat = rejoinedSplat.slice(
|
|
396
|
+
0,
|
|
397
|
+
rejoinedSplat.length - suffix.length
|
|
389
398
|
);
|
|
390
399
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
400
|
+
_splat = rejoinedSplat;
|
|
401
|
+
} else {
|
|
402
|
+
_splat = decodeURI(
|
|
403
|
+
joinPaths(remainingBaseSegments.map((d) => d.value))
|
|
404
|
+
);
|
|
394
405
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
+
params["*"] = _splat;
|
|
407
|
+
params["_splat"] = _splat;
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
if (routeSegment.type === SEGMENT_TYPE_PATHNAME) {
|
|
411
|
+
if (routeSegment.value === "/" && !(baseSegment == null ? void 0 : baseSegment.value)) {
|
|
412
|
+
routeIndex++;
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
if (baseSegment) {
|
|
416
|
+
if (caseSensitive) {
|
|
417
|
+
if (routeSegment.value !== baseSegment.value) {
|
|
406
418
|
return false;
|
|
407
419
|
}
|
|
408
|
-
|
|
409
|
-
routeIndex++;
|
|
410
|
-
continue;
|
|
411
|
-
} else {
|
|
420
|
+
} else if (routeSegment.value.toLowerCase() !== baseSegment.value.toLowerCase()) {
|
|
412
421
|
return false;
|
|
413
422
|
}
|
|
423
|
+
baseIndex++;
|
|
424
|
+
routeIndex++;
|
|
425
|
+
continue;
|
|
426
|
+
} else {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (routeSegment.type === SEGMENT_TYPE_PARAM) {
|
|
431
|
+
if (!baseSegment) {
|
|
432
|
+
return false;
|
|
414
433
|
}
|
|
415
|
-
if (
|
|
416
|
-
|
|
434
|
+
if (baseSegment.value === "/") {
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
let _paramValue = "";
|
|
438
|
+
let matched = false;
|
|
439
|
+
if (routeSegment.prefixSegment || routeSegment.suffixSegment) {
|
|
440
|
+
const prefix = routeSegment.prefixSegment || "";
|
|
441
|
+
const suffix = routeSegment.suffixSegment || "";
|
|
442
|
+
const baseValue = baseSegment.value;
|
|
443
|
+
if (prefix && !baseValue.startsWith(prefix)) {
|
|
417
444
|
return false;
|
|
418
445
|
}
|
|
419
|
-
if (
|
|
446
|
+
if (suffix && !baseValue.endsWith(suffix)) {
|
|
420
447
|
return false;
|
|
421
448
|
}
|
|
422
|
-
let
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
449
|
+
let paramValue = baseValue;
|
|
450
|
+
if (prefix && paramValue.startsWith(prefix)) {
|
|
451
|
+
paramValue = paramValue.slice(prefix.length);
|
|
452
|
+
}
|
|
453
|
+
if (suffix && paramValue.endsWith(suffix)) {
|
|
454
|
+
paramValue = paramValue.slice(0, paramValue.length - suffix.length);
|
|
455
|
+
}
|
|
456
|
+
_paramValue = decodeURIComponent(paramValue);
|
|
457
|
+
matched = true;
|
|
458
|
+
} else {
|
|
459
|
+
_paramValue = decodeURIComponent(baseSegment.value);
|
|
460
|
+
matched = true;
|
|
461
|
+
}
|
|
462
|
+
if (matched) {
|
|
463
|
+
params[routeSegment.value.substring(1)] = _paramValue;
|
|
464
|
+
baseIndex++;
|
|
465
|
+
}
|
|
466
|
+
routeIndex++;
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
469
|
+
if (routeSegment.type === SEGMENT_TYPE_OPTIONAL_PARAM) {
|
|
470
|
+
if (!baseSegment) {
|
|
471
|
+
routeIndex++;
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
if (baseSegment.value === "/") {
|
|
475
|
+
routeIndex++;
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
let _paramValue = "";
|
|
479
|
+
let matched = false;
|
|
480
|
+
if (routeSegment.prefixSegment || routeSegment.suffixSegment) {
|
|
481
|
+
const prefix = routeSegment.prefixSegment || "";
|
|
482
|
+
const suffix = routeSegment.suffixSegment || "";
|
|
483
|
+
const baseValue = baseSegment.value;
|
|
484
|
+
if ((!prefix || baseValue.startsWith(prefix)) && (!suffix || baseValue.endsWith(suffix))) {
|
|
434
485
|
let paramValue = baseValue;
|
|
435
486
|
if (prefix && paramValue.startsWith(prefix)) {
|
|
436
487
|
paramValue = paramValue.slice(prefix.length);
|
|
@@ -443,95 +494,58 @@ function matchByPath(basepath, from, matchLocation) {
|
|
|
443
494
|
}
|
|
444
495
|
_paramValue = decodeURIComponent(paramValue);
|
|
445
496
|
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
|
-
}
|
|
454
|
-
routeIndex++;
|
|
455
|
-
continue;
|
|
456
|
-
}
|
|
457
|
-
if (routeSegment.type === "optional-param") {
|
|
458
|
-
if (!baseSegment) {
|
|
459
|
-
routeIndex++;
|
|
460
|
-
continue;
|
|
461
497
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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
|
-
}
|
|
498
|
+
} else {
|
|
499
|
+
let shouldMatchOptional = true;
|
|
500
|
+
for (let lookAhead = routeIndex + 1; lookAhead < routeSegments.length; lookAhead++) {
|
|
501
|
+
const futureRouteSegment = routeSegments[lookAhead];
|
|
502
|
+
if ((futureRouteSegment == null ? void 0 : futureRouteSegment.type) === SEGMENT_TYPE_PATHNAME && futureRouteSegment.value === baseSegment.value) {
|
|
503
|
+
shouldMatchOptional = false;
|
|
504
|
+
break;
|
|
497
505
|
}
|
|
498
|
-
if (
|
|
499
|
-
|
|
500
|
-
matched = true;
|
|
506
|
+
if ((futureRouteSegment == null ? void 0 : futureRouteSegment.type) === SEGMENT_TYPE_PARAM || (futureRouteSegment == null ? void 0 : futureRouteSegment.type) === SEGMENT_TYPE_WILDCARD) {
|
|
507
|
+
break;
|
|
501
508
|
}
|
|
502
509
|
}
|
|
503
|
-
if (
|
|
504
|
-
|
|
505
|
-
|
|
510
|
+
if (shouldMatchOptional) {
|
|
511
|
+
_paramValue = decodeURIComponent(baseSegment.value);
|
|
512
|
+
matched = true;
|
|
506
513
|
}
|
|
507
|
-
routeIndex++;
|
|
508
|
-
continue;
|
|
509
514
|
}
|
|
515
|
+
if (matched) {
|
|
516
|
+
params[routeSegment.value.substring(1)] = _paramValue;
|
|
517
|
+
baseIndex++;
|
|
518
|
+
}
|
|
519
|
+
routeIndex++;
|
|
520
|
+
continue;
|
|
510
521
|
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
)
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
522
|
+
}
|
|
523
|
+
if (!isLastBaseSegment && isLastRouteSegment) {
|
|
524
|
+
params["**"] = joinPaths(
|
|
525
|
+
baseSegments.slice(baseIndex + 1).map((d) => d.value)
|
|
526
|
+
);
|
|
527
|
+
return !!fuzzy && (routeSegment == null ? void 0 : routeSegment.value) !== "/";
|
|
528
|
+
}
|
|
529
|
+
if (baseIndex < baseSegments.length && routeIndex >= routeSegments.length) {
|
|
530
|
+
return false;
|
|
531
|
+
}
|
|
532
|
+
if (routeIndex < routeSegments.length && baseIndex >= baseSegments.length) {
|
|
533
|
+
for (let i = routeIndex; i < routeSegments.length; i++) {
|
|
534
|
+
if (((_b = routeSegments[i]) == null ? void 0 : _b.type) !== SEGMENT_TYPE_OPTIONAL_PARAM) {
|
|
535
|
+
return false;
|
|
525
536
|
}
|
|
526
|
-
break;
|
|
527
537
|
}
|
|
528
538
|
break;
|
|
529
539
|
}
|
|
530
|
-
|
|
531
|
-
}
|
|
532
|
-
return
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
return true;
|
|
533
543
|
}
|
|
534
544
|
export {
|
|
545
|
+
SEGMENT_TYPE_OPTIONAL_PARAM,
|
|
546
|
+
SEGMENT_TYPE_PARAM,
|
|
547
|
+
SEGMENT_TYPE_PATHNAME,
|
|
548
|
+
SEGMENT_TYPE_WILDCARD,
|
|
535
549
|
cleanPath,
|
|
536
550
|
exactPathTest,
|
|
537
551
|
interpolatePath,
|