@tanstack/router-core 1.132.0-alpha.8 → 1.132.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Matches.cjs +2 -1
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +3 -3
- package/dist/cjs/index.cjs +7 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +8 -4
- package/dist/cjs/load-matches.cjs +5 -3
- package/dist/cjs/load-matches.cjs.map +1 -1
- package/dist/cjs/location.d.cts +38 -0
- package/dist/cjs/path.cjs +27 -64
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/path.d.cts +6 -7
- package/dist/cjs/process-route-tree.cjs +144 -0
- package/dist/cjs/process-route-tree.cjs.map +1 -0
- package/dist/cjs/process-route-tree.d.cts +10 -0
- package/dist/cjs/redirect.cjs +1 -1
- package/dist/cjs/redirect.cjs.map +1 -1
- package/dist/cjs/rewrite.cjs +63 -0
- package/dist/cjs/rewrite.cjs.map +1 -0
- package/dist/cjs/rewrite.d.cts +22 -0
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +55 -42
- package/dist/cjs/router.cjs +77 -184
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +68 -37
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.d.cts +9 -0
- package/dist/cjs/ssr/createRequestHandler.cjs +4 -1
- package/dist/cjs/ssr/createRequestHandler.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/transformer.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/transformer.d.cts +10 -8
- package/dist/cjs/ssr/server.d.cts +0 -5
- package/dist/cjs/ssr/ssr-server.cjs +5 -2
- package/dist/cjs/ssr/ssr-server.cjs.map +1 -1
- package/dist/cjs/ssr/ssr-server.d.cts +4 -1
- package/dist/cjs/utils.cjs +68 -46
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/esm/Matches.js +2 -1
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +3 -3
- package/dist/esm/index.d.ts +8 -4
- package/dist/esm/index.js +8 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/load-matches.js +5 -3
- package/dist/esm/load-matches.js.map +1 -1
- package/dist/esm/location.d.ts +38 -0
- package/dist/esm/path.d.ts +6 -7
- package/dist/esm/path.js +27 -64
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/process-route-tree.d.ts +10 -0
- package/dist/esm/process-route-tree.js +144 -0
- package/dist/esm/process-route-tree.js.map +1 -0
- package/dist/esm/redirect.js +1 -1
- package/dist/esm/redirect.js.map +1 -1
- package/dist/esm/rewrite.d.ts +22 -0
- package/dist/esm/rewrite.js +63 -0
- package/dist/esm/rewrite.js.map +1 -0
- package/dist/esm/route.d.ts +55 -42
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +68 -37
- package/dist/esm/router.js +79 -186
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/scroll-restoration.d.ts +9 -0
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/ssr/createRequestHandler.js +4 -1
- package/dist/esm/ssr/createRequestHandler.js.map +1 -1
- package/dist/esm/ssr/serializer/transformer.d.ts +10 -8
- package/dist/esm/ssr/serializer/transformer.js.map +1 -1
- package/dist/esm/ssr/server.d.ts +0 -5
- package/dist/esm/ssr/ssr-server.d.ts +4 -1
- package/dist/esm/ssr/ssr-server.js +5 -2
- package/dist/esm/ssr/ssr-server.js.map +1 -1
- package/dist/esm/utils.js +68 -46
- package/dist/esm/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/Matches.ts +2 -1
- package/src/fileRoute.ts +16 -6
- package/src/index.ts +11 -6
- package/src/load-matches.ts +29 -19
- package/src/location.ts +38 -0
- package/src/path.ts +44 -82
- package/src/process-route-tree.ts +233 -0
- package/src/redirect.ts +1 -1
- package/src/rewrite.ts +70 -0
- package/src/route.ts +214 -80
- package/src/router.ts +208 -329
- package/src/scroll-restoration.ts +1 -1
- package/src/ssr/createRequestHandler.ts +4 -1
- package/src/ssr/serializer/transformer.ts +17 -17
- package/src/ssr/server.ts +5 -5
- package/src/ssr/ssr-server.ts +8 -5
- package/src/utils.ts +83 -61
package/dist/cjs/router.cjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const store = require("@tanstack/store");
|
|
4
4
|
const history = require("@tanstack/history");
|
|
5
|
-
const invariant = require("tiny-invariant");
|
|
6
5
|
const utils = require("./utils.cjs");
|
|
6
|
+
const processRouteTree = require("./process-route-tree.cjs");
|
|
7
7
|
const path = require("./path.cjs");
|
|
8
8
|
const notFound = require("./not-found.cjs");
|
|
9
9
|
const scrollRestoration = require("./scroll-restoration.cjs");
|
|
@@ -12,6 +12,7 @@ const root = require("./root.cjs");
|
|
|
12
12
|
const redirect = require("./redirect.cjs");
|
|
13
13
|
const lruCache = require("./lru-cache.cjs");
|
|
14
14
|
const loadMatches = require("./load-matches.cjs");
|
|
15
|
+
const rewrite = require("./rewrite.cjs");
|
|
15
16
|
function defaultSerializeError(err) {
|
|
16
17
|
if (err instanceof Error) {
|
|
17
18
|
const obj = {
|
|
@@ -56,7 +57,6 @@ class RouterCore {
|
|
|
56
57
|
"The notFoundRoute API is deprecated and will be removed in the next major version. See https://tanstack.com/router/v1/docs/framework/react/guide/not-found-errors#migrating-from-notfoundroute for more info."
|
|
57
58
|
);
|
|
58
59
|
}
|
|
59
|
-
const previousOptions = this.options;
|
|
60
60
|
this.options = {
|
|
61
61
|
...this.options,
|
|
62
62
|
...newOptions
|
|
@@ -68,24 +68,43 @@ class RouterCore {
|
|
|
68
68
|
char
|
|
69
69
|
])
|
|
70
70
|
) : void 0;
|
|
71
|
-
if (!this.
|
|
72
|
-
if (
|
|
73
|
-
this.
|
|
71
|
+
if (!this.history || this.options.history && this.options.history !== this.history) {
|
|
72
|
+
if (!this.options.history) {
|
|
73
|
+
if (!this.isServer) {
|
|
74
|
+
this.history = history.createBrowserHistory();
|
|
75
|
+
}
|
|
74
76
|
} else {
|
|
75
|
-
this.
|
|
77
|
+
this.history = this.options.history;
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
})
|
|
80
|
+
if (this.options.basepath) {
|
|
81
|
+
const basepathRewrite = rewrite.rewriteBasepath({
|
|
82
|
+
basepath: this.options.basepath
|
|
83
|
+
});
|
|
84
|
+
if (this.options.rewrite) {
|
|
85
|
+
this.rewrite = rewrite.composeRewrites([basepathRewrite, this.options.rewrite]);
|
|
86
|
+
} else {
|
|
87
|
+
this.rewrite = basepathRewrite;
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
this.rewrite = this.options.rewrite;
|
|
91
|
+
}
|
|
92
|
+
this.origin = this.options.origin;
|
|
93
|
+
if (!this.origin) {
|
|
94
|
+
if (!this.isServer) {
|
|
95
|
+
this.origin = window.origin;
|
|
96
|
+
} else {
|
|
97
|
+
this.origin = "http://localhost";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (this.history) {
|
|
82
101
|
this.updateLatestLocation();
|
|
83
102
|
}
|
|
84
103
|
if (this.options.routeTree !== this.routeTree) {
|
|
85
104
|
this.routeTree = this.options.routeTree;
|
|
86
105
|
this.buildRouteTree();
|
|
87
106
|
}
|
|
88
|
-
if (!this.__store) {
|
|
107
|
+
if (!this.__store && this.latestLocation) {
|
|
89
108
|
this.__store = new store.Store(getInitialRouterState(this.latestLocation), {
|
|
90
109
|
onUpdate: () => {
|
|
91
110
|
this.__store.state = {
|
|
@@ -111,7 +130,7 @@ class RouterCore {
|
|
|
111
130
|
);
|
|
112
131
|
};
|
|
113
132
|
this.buildRouteTree = () => {
|
|
114
|
-
const { routesById, routesByPath, flatRoutes } = processRouteTree({
|
|
133
|
+
const { routesById, routesByPath, flatRoutes } = processRouteTree.processRouteTree({
|
|
115
134
|
routeTree: this.routeTree,
|
|
116
135
|
initRoute: (route, i) => {
|
|
117
136
|
route.init({
|
|
@@ -149,19 +168,24 @@ class RouterCore {
|
|
|
149
168
|
};
|
|
150
169
|
this.parseLocation = (locationToParse, previousLocation) => {
|
|
151
170
|
const parse = ({
|
|
152
|
-
|
|
153
|
-
search,
|
|
154
|
-
hash,
|
|
171
|
+
href,
|
|
155
172
|
state
|
|
156
173
|
}) => {
|
|
157
|
-
const
|
|
174
|
+
const fullUrl = new URL(href, this.origin);
|
|
175
|
+
const url = rewrite.executeRewriteInput(this.rewrite, fullUrl);
|
|
176
|
+
const parsedSearch = this.options.parseSearch(url.search);
|
|
158
177
|
const searchStr = this.options.stringifySearch(parsedSearch);
|
|
178
|
+
url.search = searchStr;
|
|
179
|
+
const fullPath = url.href.replace(url.origin, "");
|
|
180
|
+
const { pathname, hash } = url;
|
|
159
181
|
return {
|
|
182
|
+
href: fullPath,
|
|
183
|
+
publicHref: href,
|
|
184
|
+
url: url.href,
|
|
160
185
|
pathname,
|
|
161
186
|
searchStr,
|
|
162
187
|
search: utils.replaceEqualDeep(previousLocation?.search, parsedSearch),
|
|
163
188
|
hash: hash.split("#").reverse()[0] ?? "",
|
|
164
|
-
href: `${pathname}${searchStr}${hash}`,
|
|
165
189
|
state: utils.replaceEqualDeep(previousLocation?.state, state)
|
|
166
190
|
};
|
|
167
191
|
};
|
|
@@ -181,11 +205,9 @@ class RouterCore {
|
|
|
181
205
|
};
|
|
182
206
|
this.resolvePathWithBase = (from, path$1) => {
|
|
183
207
|
const resolvedPath = path.resolvePath({
|
|
184
|
-
basepath: this.basepath,
|
|
185
208
|
base: from,
|
|
186
209
|
to: path.cleanPath(path$1),
|
|
187
210
|
trailingSlash: this.options.trailingSlash,
|
|
188
|
-
caseSensitive: this.options.caseSensitive,
|
|
189
211
|
parseCache: this.parsePathnameCache
|
|
190
212
|
});
|
|
191
213
|
return resolvedPath;
|
|
@@ -207,7 +229,6 @@ class RouterCore {
|
|
|
207
229
|
return getMatchedRoutes({
|
|
208
230
|
pathname,
|
|
209
231
|
routePathname,
|
|
210
|
-
basepath: this.basepath,
|
|
211
232
|
caseSensitive: this.options.caseSensitive,
|
|
212
233
|
routesByPath: this.routesByPath,
|
|
213
234
|
routesById: this.routesById,
|
|
@@ -315,13 +336,18 @@ class RouterCore {
|
|
|
315
336
|
const hashStr = hash ? `#${hash}` : "";
|
|
316
337
|
let nextState = dest.state === true ? currentLocation.state : dest.state ? utils.functionalUpdate(dest.state, currentLocation.state) : {};
|
|
317
338
|
nextState = utils.replaceEqualDeep(currentLocation.state, nextState);
|
|
339
|
+
const fullPath = `${nextPathname}${searchStr}${hashStr}`;
|
|
340
|
+
const url = new URL(fullPath, this.origin);
|
|
341
|
+
const rewrittenUrl = rewrite.executeRewriteOutput(this.rewrite, url);
|
|
318
342
|
return {
|
|
343
|
+
publicHref: rewrittenUrl.pathname + rewrittenUrl.search + rewrittenUrl.hash,
|
|
344
|
+
href: fullPath,
|
|
345
|
+
url: rewrittenUrl.href,
|
|
319
346
|
pathname: nextPathname,
|
|
320
347
|
search: nextSearch,
|
|
321
348
|
searchStr,
|
|
322
349
|
state: nextState,
|
|
323
350
|
hash: hash ?? "",
|
|
324
|
-
href: `${nextPathname}${searchStr}${hashStr}`,
|
|
325
351
|
unmaskOnReload: dest.unmaskOnReload
|
|
326
352
|
};
|
|
327
353
|
};
|
|
@@ -332,7 +358,6 @@ class RouterCore {
|
|
|
332
358
|
let params = {};
|
|
333
359
|
const foundMask = this.options.routeMasks?.find((d) => {
|
|
334
360
|
const match = path.matchPathname(
|
|
335
|
-
this.basepath,
|
|
336
361
|
next.pathname,
|
|
337
362
|
{
|
|
338
363
|
to: d.from,
|
|
@@ -358,8 +383,7 @@ class RouterCore {
|
|
|
358
383
|
}
|
|
359
384
|
}
|
|
360
385
|
if (maskedNext) {
|
|
361
|
-
|
|
362
|
-
next.maskedLocation = maskedFinal;
|
|
386
|
+
next.maskedLocation = maskedNext;
|
|
363
387
|
}
|
|
364
388
|
return next;
|
|
365
389
|
};
|
|
@@ -393,7 +417,7 @@ class RouterCore {
|
|
|
393
417
|
});
|
|
394
418
|
return isEqual;
|
|
395
419
|
};
|
|
396
|
-
const isSameUrl = this.latestLocation.href === next.href;
|
|
420
|
+
const isSameUrl = path.trimPathRight(this.latestLocation.href) === path.trimPathRight(next.href);
|
|
397
421
|
const previousCommitPromise = this.commitLocationPromise;
|
|
398
422
|
this.commitLocationPromise = utils.createControlledPromise(() => {
|
|
399
423
|
previousCommitPromise?.resolve();
|
|
@@ -429,7 +453,7 @@ class RouterCore {
|
|
|
429
453
|
nextHistory.state.__hashScrollIntoViewOptions = hashScrollIntoView ?? this.options.defaultHashScrollIntoView ?? true;
|
|
430
454
|
this.shouldViewTransition = viewTransition;
|
|
431
455
|
this.history[next.replace ? "replace" : "push"](
|
|
432
|
-
nextHistory.
|
|
456
|
+
nextHistory.publicHref,
|
|
433
457
|
nextHistory.state,
|
|
434
458
|
{ ignoreBlocker }
|
|
435
459
|
);
|
|
@@ -482,7 +506,7 @@ class RouterCore {
|
|
|
482
506
|
if (reloadDocument) {
|
|
483
507
|
if (!href) {
|
|
484
508
|
const location = this.buildLocation({ to, ...rest });
|
|
485
|
-
href =
|
|
509
|
+
href = location.href;
|
|
486
510
|
}
|
|
487
511
|
if (rest.replace) {
|
|
488
512
|
window.location.replace(href);
|
|
@@ -829,7 +853,6 @@ class RouterCore {
|
|
|
829
853
|
const pending = opts?.pending === void 0 ? !this.state.isLoading : opts.pending;
|
|
830
854
|
const baseLocation = pending ? this.latestLocation : this.state.resolvedLocation || this.state.location;
|
|
831
855
|
const match = path.matchPathname(
|
|
832
|
-
this.basepath,
|
|
833
856
|
baseLocation.pathname,
|
|
834
857
|
{
|
|
835
858
|
...opts,
|
|
@@ -915,25 +938,6 @@ class RouterCore {
|
|
|
915
938
|
}
|
|
916
939
|
return root.rootRouteId;
|
|
917
940
|
})();
|
|
918
|
-
const parseErrors = matchedRoutes.map((route) => {
|
|
919
|
-
let parsedParamsError;
|
|
920
|
-
const parseParams = route.options.params?.parse ?? route.options.parseParams;
|
|
921
|
-
if (parseParams) {
|
|
922
|
-
try {
|
|
923
|
-
const parsedParams = parseParams(routeParams);
|
|
924
|
-
Object.assign(routeParams, parsedParams);
|
|
925
|
-
} catch (err) {
|
|
926
|
-
parsedParamsError = new PathParamError(err.message, {
|
|
927
|
-
cause: err
|
|
928
|
-
});
|
|
929
|
-
if (opts?.throwOnError) {
|
|
930
|
-
throw parsedParamsError;
|
|
931
|
-
}
|
|
932
|
-
return parsedParamsError;
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
return;
|
|
936
|
-
});
|
|
937
941
|
const matches = [];
|
|
938
942
|
const getParentContext = (parentMatch) => {
|
|
939
943
|
const parentMatchId = parentMatch?.id;
|
|
@@ -972,7 +976,7 @@ class RouterCore {
|
|
|
972
976
|
search: preMatchSearch
|
|
973
977
|
}) ?? "";
|
|
974
978
|
const loaderDepsHash = loaderDeps ? JSON.stringify(loaderDeps) : "";
|
|
975
|
-
const {
|
|
979
|
+
const { interpolatedPath, usedParams } = path.interpolatePath({
|
|
976
980
|
path: route.fullPath,
|
|
977
981
|
params: routeParams,
|
|
978
982
|
decodeCharMap: this.pathParamsDecodeCharMap
|
|
@@ -988,6 +992,27 @@ class RouterCore {
|
|
|
988
992
|
const previousMatch = this.state.matches.find(
|
|
989
993
|
(d) => d.routeId === route.id
|
|
990
994
|
);
|
|
995
|
+
const strictParams = existingMatch?._strictParams ?? usedParams;
|
|
996
|
+
let paramsError = void 0;
|
|
997
|
+
if (!existingMatch) {
|
|
998
|
+
const strictParseParams = route.options.params?.parse ?? route.options.parseParams;
|
|
999
|
+
if (strictParseParams) {
|
|
1000
|
+
try {
|
|
1001
|
+
Object.assign(
|
|
1002
|
+
strictParams,
|
|
1003
|
+
strictParseParams(strictParams)
|
|
1004
|
+
);
|
|
1005
|
+
} catch (err) {
|
|
1006
|
+
paramsError = new PathParamError(err.message, {
|
|
1007
|
+
cause: err
|
|
1008
|
+
});
|
|
1009
|
+
if (opts?.throwOnError) {
|
|
1010
|
+
throw paramsError;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
Object.assign(routeParams, strictParams);
|
|
991
1016
|
const cause = previousMatch ? "stay" : "enter";
|
|
992
1017
|
let match;
|
|
993
1018
|
if (existingMatch) {
|
|
@@ -995,7 +1020,7 @@ class RouterCore {
|
|
|
995
1020
|
...existingMatch,
|
|
996
1021
|
cause,
|
|
997
1022
|
params: previousMatch ? utils.replaceEqualDeep(previousMatch.params, routeParams) : routeParams,
|
|
998
|
-
_strictParams:
|
|
1023
|
+
_strictParams: strictParams,
|
|
999
1024
|
search: previousMatch ? utils.replaceEqualDeep(previousMatch.search, preMatchSearch) : utils.replaceEqualDeep(existingMatch.search, preMatchSearch),
|
|
1000
1025
|
_strictSearch: strictMatchSearch
|
|
1001
1026
|
};
|
|
@@ -1006,8 +1031,8 @@ class RouterCore {
|
|
|
1006
1031
|
index,
|
|
1007
1032
|
routeId: route.id,
|
|
1008
1033
|
params: previousMatch ? utils.replaceEqualDeep(previousMatch.params, routeParams) : routeParams,
|
|
1009
|
-
_strictParams:
|
|
1010
|
-
pathname:
|
|
1034
|
+
_strictParams: strictParams,
|
|
1035
|
+
pathname: interpolatedPath,
|
|
1011
1036
|
updatedAt: Date.now(),
|
|
1012
1037
|
search: previousMatch ? utils.replaceEqualDeep(previousMatch.search, preMatchSearch) : preMatchSearch,
|
|
1013
1038
|
_strictSearch: strictMatchSearch,
|
|
@@ -1015,7 +1040,7 @@ class RouterCore {
|
|
|
1015
1040
|
status,
|
|
1016
1041
|
isFetching: false,
|
|
1017
1042
|
error: void 0,
|
|
1018
|
-
paramsError
|
|
1043
|
+
paramsError,
|
|
1019
1044
|
__routeContext: void 0,
|
|
1020
1045
|
_nonReactive: {
|
|
1021
1046
|
loadPromise: utils.createControlledPromise()
|
|
@@ -1127,139 +1152,9 @@ function validateSearch(validateSearch2, input) {
|
|
|
1127
1152
|
}
|
|
1128
1153
|
return {};
|
|
1129
1154
|
}
|
|
1130
|
-
const REQUIRED_PARAM_BASE_SCORE = 0.5;
|
|
1131
|
-
const OPTIONAL_PARAM_BASE_SCORE = 0.4;
|
|
1132
|
-
const WILDCARD_PARAM_BASE_SCORE = 0.25;
|
|
1133
|
-
const BOTH_PRESENCE_BASE_SCORE = 0.05;
|
|
1134
|
-
const PREFIX_PRESENCE_BASE_SCORE = 0.02;
|
|
1135
|
-
const SUFFIX_PRESENCE_BASE_SCORE = 0.01;
|
|
1136
|
-
const PREFIX_LENGTH_SCORE_MULTIPLIER = 2e-4;
|
|
1137
|
-
const SUFFIX_LENGTH_SCORE_MULTIPLIER = 1e-4;
|
|
1138
|
-
function handleParam(segment, baseScore) {
|
|
1139
|
-
if (segment.prefixSegment && segment.suffixSegment) {
|
|
1140
|
-
return baseScore + BOTH_PRESENCE_BASE_SCORE + PREFIX_LENGTH_SCORE_MULTIPLIER * segment.prefixSegment.length + SUFFIX_LENGTH_SCORE_MULTIPLIER * segment.suffixSegment.length;
|
|
1141
|
-
}
|
|
1142
|
-
if (segment.prefixSegment) {
|
|
1143
|
-
return baseScore + PREFIX_PRESENCE_BASE_SCORE + PREFIX_LENGTH_SCORE_MULTIPLIER * segment.prefixSegment.length;
|
|
1144
|
-
}
|
|
1145
|
-
if (segment.suffixSegment) {
|
|
1146
|
-
return baseScore + SUFFIX_PRESENCE_BASE_SCORE + SUFFIX_LENGTH_SCORE_MULTIPLIER * segment.suffixSegment.length;
|
|
1147
|
-
}
|
|
1148
|
-
return baseScore;
|
|
1149
|
-
}
|
|
1150
|
-
function processRouteTree({
|
|
1151
|
-
routeTree,
|
|
1152
|
-
initRoute
|
|
1153
|
-
}) {
|
|
1154
|
-
const routesById = {};
|
|
1155
|
-
const routesByPath = {};
|
|
1156
|
-
const recurseRoutes = (childRoutes) => {
|
|
1157
|
-
childRoutes.forEach((childRoute, i) => {
|
|
1158
|
-
initRoute?.(childRoute, i);
|
|
1159
|
-
const existingRoute = routesById[childRoute.id];
|
|
1160
|
-
invariant(
|
|
1161
|
-
!existingRoute,
|
|
1162
|
-
`Duplicate routes found with id: ${String(childRoute.id)}`
|
|
1163
|
-
);
|
|
1164
|
-
routesById[childRoute.id] = childRoute;
|
|
1165
|
-
if (!childRoute.isRoot && childRoute.path) {
|
|
1166
|
-
const trimmedFullPath = path.trimPathRight(childRoute.fullPath);
|
|
1167
|
-
if (!routesByPath[trimmedFullPath] || childRoute.fullPath.endsWith("/")) {
|
|
1168
|
-
routesByPath[trimmedFullPath] = childRoute;
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
const children = childRoute.children;
|
|
1172
|
-
if (children?.length) {
|
|
1173
|
-
recurseRoutes(children);
|
|
1174
|
-
}
|
|
1175
|
-
});
|
|
1176
|
-
};
|
|
1177
|
-
recurseRoutes([routeTree]);
|
|
1178
|
-
const scoredRoutes = [];
|
|
1179
|
-
const routes = Object.values(routesById);
|
|
1180
|
-
routes.forEach((d, i) => {
|
|
1181
|
-
if (d.isRoot || !d.path) {
|
|
1182
|
-
return;
|
|
1183
|
-
}
|
|
1184
|
-
const trimmed = path.trimPathLeft(d.fullPath);
|
|
1185
|
-
let parsed = path.parsePathname(trimmed);
|
|
1186
|
-
let skip = 0;
|
|
1187
|
-
while (parsed.length > skip + 1 && parsed[skip]?.value === "/") {
|
|
1188
|
-
skip++;
|
|
1189
|
-
}
|
|
1190
|
-
if (skip > 0) parsed = parsed.slice(skip);
|
|
1191
|
-
let optionalParamCount = 0;
|
|
1192
|
-
let hasStaticAfter = false;
|
|
1193
|
-
const scores = parsed.map((segment, index) => {
|
|
1194
|
-
if (segment.value === "/") {
|
|
1195
|
-
return 0.75;
|
|
1196
|
-
}
|
|
1197
|
-
let baseScore = void 0;
|
|
1198
|
-
if (segment.type === path.SEGMENT_TYPE_PARAM) {
|
|
1199
|
-
baseScore = REQUIRED_PARAM_BASE_SCORE;
|
|
1200
|
-
} else if (segment.type === path.SEGMENT_TYPE_OPTIONAL_PARAM) {
|
|
1201
|
-
baseScore = OPTIONAL_PARAM_BASE_SCORE;
|
|
1202
|
-
optionalParamCount++;
|
|
1203
|
-
} else if (segment.type === path.SEGMENT_TYPE_WILDCARD) {
|
|
1204
|
-
baseScore = WILDCARD_PARAM_BASE_SCORE;
|
|
1205
|
-
}
|
|
1206
|
-
if (baseScore) {
|
|
1207
|
-
for (let i2 = index + 1; i2 < parsed.length; i2++) {
|
|
1208
|
-
const nextSegment = parsed[i2];
|
|
1209
|
-
if (nextSegment.type === path.SEGMENT_TYPE_PATHNAME && nextSegment.value !== "/") {
|
|
1210
|
-
hasStaticAfter = true;
|
|
1211
|
-
return handleParam(segment, baseScore + 0.2);
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
return handleParam(segment, baseScore);
|
|
1215
|
-
}
|
|
1216
|
-
return 1;
|
|
1217
|
-
});
|
|
1218
|
-
scoredRoutes.push({
|
|
1219
|
-
child: d,
|
|
1220
|
-
trimmed,
|
|
1221
|
-
parsed,
|
|
1222
|
-
index: i,
|
|
1223
|
-
scores,
|
|
1224
|
-
optionalParamCount,
|
|
1225
|
-
hasStaticAfter
|
|
1226
|
-
});
|
|
1227
|
-
});
|
|
1228
|
-
const flatRoutes = scoredRoutes.sort((a, b) => {
|
|
1229
|
-
const minLength = Math.min(a.scores.length, b.scores.length);
|
|
1230
|
-
for (let i = 0; i < minLength; i++) {
|
|
1231
|
-
if (a.scores[i] !== b.scores[i]) {
|
|
1232
|
-
return b.scores[i] - a.scores[i];
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
if (a.scores.length !== b.scores.length) {
|
|
1236
|
-
if (a.optionalParamCount !== b.optionalParamCount) {
|
|
1237
|
-
if (a.hasStaticAfter === b.hasStaticAfter) {
|
|
1238
|
-
return a.optionalParamCount - b.optionalParamCount;
|
|
1239
|
-
} else if (a.hasStaticAfter && !b.hasStaticAfter) {
|
|
1240
|
-
return -1;
|
|
1241
|
-
} else if (!a.hasStaticAfter && b.hasStaticAfter) {
|
|
1242
|
-
return 1;
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
return b.scores.length - a.scores.length;
|
|
1246
|
-
}
|
|
1247
|
-
for (let i = 0; i < minLength; i++) {
|
|
1248
|
-
if (a.parsed[i].value !== b.parsed[i].value) {
|
|
1249
|
-
return a.parsed[i].value > b.parsed[i].value ? 1 : -1;
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
return a.index - b.index;
|
|
1253
|
-
}).map((d, i) => {
|
|
1254
|
-
d.child.rank = i;
|
|
1255
|
-
return d.child;
|
|
1256
|
-
});
|
|
1257
|
-
return { routesById, routesByPath, flatRoutes };
|
|
1258
|
-
}
|
|
1259
1155
|
function getMatchedRoutes({
|
|
1260
1156
|
pathname,
|
|
1261
1157
|
routePathname,
|
|
1262
|
-
basepath,
|
|
1263
1158
|
caseSensitive,
|
|
1264
1159
|
routesByPath,
|
|
1265
1160
|
routesById,
|
|
@@ -1270,7 +1165,6 @@ function getMatchedRoutes({
|
|
|
1270
1165
|
const trimmedPath = path.trimPathRight(pathname);
|
|
1271
1166
|
const getMatchedParams = (route) => {
|
|
1272
1167
|
const result = path.matchPathname(
|
|
1273
|
-
basepath,
|
|
1274
1168
|
trimmedPath,
|
|
1275
1169
|
{
|
|
1276
1170
|
to: route.fullPath,
|
|
@@ -1400,5 +1294,4 @@ exports.getInitialRouterState = getInitialRouterState;
|
|
|
1400
1294
|
exports.getLocationChangeInfo = getLocationChangeInfo;
|
|
1401
1295
|
exports.getMatchedRoutes = getMatchedRoutes;
|
|
1402
1296
|
exports.lazyFn = lazyFn;
|
|
1403
|
-
exports.processRouteTree = processRouteTree;
|
|
1404
1297
|
//# sourceMappingURL=router.cjs.map
|