@tanstack/router-core 1.121.15 → 1.121.17

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.
Files changed (125) hide show
  1. package/package.json +1 -1
  2. package/src/redirect.ts +3 -0
  3. package/src/router.ts +15 -4
  4. package/dist/cjs/Matches.cjs +0 -13
  5. package/dist/cjs/Matches.cjs.map +0 -1
  6. package/dist/cjs/Matches.d.cts +0 -109
  7. package/dist/cjs/RouterProvider.d.cts +0 -26
  8. package/dist/cjs/defer.cjs +0 -25
  9. package/dist/cjs/defer.cjs.map +0 -1
  10. package/dist/cjs/defer.d.cts +0 -20
  11. package/dist/cjs/fileRoute.d.cts +0 -23
  12. package/dist/cjs/history.d.cts +0 -8
  13. package/dist/cjs/index.cjs +0 -79
  14. package/dist/cjs/index.cjs.map +0 -1
  15. package/dist/cjs/index.d.cts +0 -41
  16. package/dist/cjs/link.cjs +0 -5
  17. package/dist/cjs/link.cjs.map +0 -1
  18. package/dist/cjs/link.d.cts +0 -212
  19. package/dist/cjs/location.d.cts +0 -12
  20. package/dist/cjs/manifest.d.cts +0 -24
  21. package/dist/cjs/not-found.cjs +0 -13
  22. package/dist/cjs/not-found.cjs.map +0 -1
  23. package/dist/cjs/not-found.d.cts +0 -20
  24. package/dist/cjs/path.cjs +0 -412
  25. package/dist/cjs/path.cjs.map +0 -1
  26. package/dist/cjs/path.d.cts +0 -56
  27. package/dist/cjs/qss.cjs +0 -36
  28. package/dist/cjs/qss.cjs.map +0 -1
  29. package/dist/cjs/qss.d.cts +0 -31
  30. package/dist/cjs/redirect.cjs +0 -39
  31. package/dist/cjs/redirect.cjs.map +0 -1
  32. package/dist/cjs/redirect.d.cts +0 -41
  33. package/dist/cjs/root.cjs +0 -5
  34. package/dist/cjs/root.cjs.map +0 -1
  35. package/dist/cjs/root.d.cts +0 -2
  36. package/dist/cjs/route.cjs +0 -119
  37. package/dist/cjs/route.cjs.map +0 -1
  38. package/dist/cjs/route.d.cts +0 -432
  39. package/dist/cjs/routeInfo.d.cts +0 -54
  40. package/dist/cjs/router.cjs +0 -1795
  41. package/dist/cjs/router.cjs.map +0 -1
  42. package/dist/cjs/router.d.cts +0 -627
  43. package/dist/cjs/scroll-restoration.cjs +0 -207
  44. package/dist/cjs/scroll-restoration.cjs.map +0 -1
  45. package/dist/cjs/scroll-restoration.d.cts +0 -38
  46. package/dist/cjs/searchMiddleware.cjs +0 -42
  47. package/dist/cjs/searchMiddleware.cjs.map +0 -1
  48. package/dist/cjs/searchMiddleware.d.cts +0 -5
  49. package/dist/cjs/searchParams.cjs +0 -61
  50. package/dist/cjs/searchParams.cjs.map +0 -1
  51. package/dist/cjs/searchParams.d.cts +0 -7
  52. package/dist/cjs/serializer.d.cts +0 -22
  53. package/dist/cjs/structuralSharing.d.cts +0 -4
  54. package/dist/cjs/typePrimitives.d.cts +0 -65
  55. package/dist/cjs/useLoaderData.d.cts +0 -5
  56. package/dist/cjs/useLoaderDeps.d.cts +0 -5
  57. package/dist/cjs/useNavigate.d.cts +0 -3
  58. package/dist/cjs/useParams.d.cts +0 -5
  59. package/dist/cjs/useRouteContext.d.cts +0 -9
  60. package/dist/cjs/useSearch.d.cts +0 -5
  61. package/dist/cjs/utils.cjs +0 -165
  62. package/dist/cjs/utils.cjs.map +0 -1
  63. package/dist/cjs/utils.d.cts +0 -94
  64. package/dist/cjs/validators.d.cts +0 -51
  65. package/dist/esm/Matches.d.ts +0 -109
  66. package/dist/esm/Matches.js +0 -13
  67. package/dist/esm/Matches.js.map +0 -1
  68. package/dist/esm/RouterProvider.d.ts +0 -26
  69. package/dist/esm/defer.d.ts +0 -20
  70. package/dist/esm/defer.js +0 -25
  71. package/dist/esm/defer.js.map +0 -1
  72. package/dist/esm/fileRoute.d.ts +0 -23
  73. package/dist/esm/history.d.ts +0 -8
  74. package/dist/esm/index.d.ts +0 -41
  75. package/dist/esm/index.js +0 -79
  76. package/dist/esm/index.js.map +0 -1
  77. package/dist/esm/link.d.ts +0 -212
  78. package/dist/esm/link.js +0 -5
  79. package/dist/esm/link.js.map +0 -1
  80. package/dist/esm/location.d.ts +0 -12
  81. package/dist/esm/manifest.d.ts +0 -24
  82. package/dist/esm/not-found.d.ts +0 -20
  83. package/dist/esm/not-found.js +0 -13
  84. package/dist/esm/not-found.js.map +0 -1
  85. package/dist/esm/path.d.ts +0 -56
  86. package/dist/esm/path.js +0 -412
  87. package/dist/esm/path.js.map +0 -1
  88. package/dist/esm/qss.d.ts +0 -31
  89. package/dist/esm/qss.js +0 -36
  90. package/dist/esm/qss.js.map +0 -1
  91. package/dist/esm/redirect.d.ts +0 -41
  92. package/dist/esm/redirect.js +0 -39
  93. package/dist/esm/redirect.js.map +0 -1
  94. package/dist/esm/root.d.ts +0 -2
  95. package/dist/esm/root.js +0 -5
  96. package/dist/esm/root.js.map +0 -1
  97. package/dist/esm/route.d.ts +0 -432
  98. package/dist/esm/route.js +0 -119
  99. package/dist/esm/route.js.map +0 -1
  100. package/dist/esm/routeInfo.d.ts +0 -54
  101. package/dist/esm/router.d.ts +0 -627
  102. package/dist/esm/router.js +0 -1795
  103. package/dist/esm/router.js.map +0 -1
  104. package/dist/esm/scroll-restoration.d.ts +0 -38
  105. package/dist/esm/scroll-restoration.js +0 -207
  106. package/dist/esm/scroll-restoration.js.map +0 -1
  107. package/dist/esm/searchMiddleware.d.ts +0 -5
  108. package/dist/esm/searchMiddleware.js +0 -42
  109. package/dist/esm/searchMiddleware.js.map +0 -1
  110. package/dist/esm/searchParams.d.ts +0 -7
  111. package/dist/esm/searchParams.js +0 -61
  112. package/dist/esm/searchParams.js.map +0 -1
  113. package/dist/esm/serializer.d.ts +0 -22
  114. package/dist/esm/structuralSharing.d.ts +0 -4
  115. package/dist/esm/typePrimitives.d.ts +0 -65
  116. package/dist/esm/useLoaderData.d.ts +0 -5
  117. package/dist/esm/useLoaderDeps.d.ts +0 -5
  118. package/dist/esm/useNavigate.d.ts +0 -3
  119. package/dist/esm/useParams.d.ts +0 -5
  120. package/dist/esm/useRouteContext.d.ts +0 -9
  121. package/dist/esm/useSearch.d.ts +0 -5
  122. package/dist/esm/utils.d.ts +0 -94
  123. package/dist/esm/utils.js +0 -165
  124. package/dist/esm/utils.js.map +0 -1
  125. package/dist/esm/validators.d.ts +0 -51
@@ -1,1795 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const store = require("@tanstack/store");
4
- const history = require("@tanstack/history");
5
- const invariant = require("tiny-invariant");
6
- const utils = require("./utils.cjs");
7
- const path = require("./path.cjs");
8
- const notFound = require("./not-found.cjs");
9
- const scrollRestoration = require("./scroll-restoration.cjs");
10
- const searchParams = require("./searchParams.cjs");
11
- const root = require("./root.cjs");
12
- const redirect = require("./redirect.cjs");
13
- function defaultSerializeError(err) {
14
- if (err instanceof Error) {
15
- const obj = {
16
- name: err.name,
17
- message: err.message
18
- };
19
- if (process.env.NODE_ENV === "development") {
20
- obj.stack = err.stack;
21
- }
22
- return obj;
23
- }
24
- return {
25
- data: err
26
- };
27
- }
28
- function getLocationChangeInfo(routerState) {
29
- const fromLocation = routerState.resolvedLocation;
30
- const toLocation = routerState.location;
31
- const pathChanged = (fromLocation == null ? void 0 : fromLocation.pathname) !== toLocation.pathname;
32
- const hrefChanged = (fromLocation == null ? void 0 : fromLocation.href) !== toLocation.href;
33
- const hashChanged = (fromLocation == null ? void 0 : fromLocation.hash) !== toLocation.hash;
34
- return { fromLocation, toLocation, pathChanged, hrefChanged, hashChanged };
35
- }
36
- class RouterCore {
37
- /**
38
- * @deprecated Use the `createRouter` function instead
39
- */
40
- constructor(options) {
41
- this.tempLocationKey = `${Math.round(
42
- Math.random() * 1e7
43
- )}`;
44
- this.resetNextScroll = true;
45
- this.shouldViewTransition = void 0;
46
- this.isViewTransitionTypesSupported = void 0;
47
- this.subscribers = /* @__PURE__ */ new Set();
48
- this.isScrollRestoring = false;
49
- this.isScrollRestorationSetup = false;
50
- this.startTransition = (fn) => fn();
51
- this.isShell = false;
52
- this.update = (newOptions) => {
53
- var _a;
54
- if (newOptions.notFoundRoute) {
55
- console.warn(
56
- "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
- }
59
- const previousOptions = this.options;
60
- this.options = {
61
- ...this.options,
62
- ...newOptions
63
- };
64
- this.isServer = this.options.isServer ?? typeof document === "undefined";
65
- this.pathParamsDecodeCharMap = this.options.pathParamsAllowedCharacters ? new Map(
66
- this.options.pathParamsAllowedCharacters.map((char) => [
67
- encodeURIComponent(char),
68
- char
69
- ])
70
- ) : void 0;
71
- if (!this.basepath || newOptions.basepath && newOptions.basepath !== previousOptions.basepath) {
72
- if (newOptions.basepath === void 0 || newOptions.basepath === "" || newOptions.basepath === "/") {
73
- this.basepath = "/";
74
- } else {
75
- this.basepath = `/${path.trimPath(newOptions.basepath)}`;
76
- }
77
- }
78
- if (!this.history || this.options.history && this.options.history !== this.history) {
79
- this.history = this.options.history ?? (this.isServer ? history.createMemoryHistory({
80
- initialEntries: [this.basepath || "/"]
81
- }) : history.createBrowserHistory());
82
- this.latestLocation = this.parseLocation();
83
- }
84
- if (this.options.routeTree !== this.routeTree) {
85
- this.routeTree = this.options.routeTree;
86
- this.buildRouteTree();
87
- }
88
- if (!this.__store) {
89
- this.__store = new store.Store(getInitialRouterState(this.latestLocation), {
90
- onUpdate: () => {
91
- this.__store.state = {
92
- ...this.state,
93
- cachedMatches: this.state.cachedMatches.filter(
94
- (d) => !["redirected"].includes(d.status)
95
- )
96
- };
97
- }
98
- });
99
- scrollRestoration.setupScrollRestoration(this);
100
- }
101
- if (typeof window !== "undefined" && "CSS" in window && typeof ((_a = window.CSS) == null ? void 0 : _a.supports) === "function") {
102
- this.isViewTransitionTypesSupported = window.CSS.supports(
103
- "selector(:active-view-transition-type(a)"
104
- );
105
- }
106
- if (this.latestLocation.search.__TSS_SHELL) {
107
- this.isShell = true;
108
- }
109
- };
110
- this.buildRouteTree = () => {
111
- const { routesById, routesByPath, flatRoutes } = processRouteTree({
112
- routeTree: this.routeTree,
113
- initRoute: (route, i) => {
114
- route.init({
115
- originalIndex: i,
116
- defaultSsr: this.options.defaultSsr
117
- });
118
- }
119
- });
120
- this.routesById = routesById;
121
- this.routesByPath = routesByPath;
122
- this.flatRoutes = flatRoutes;
123
- const notFoundRoute = this.options.notFoundRoute;
124
- if (notFoundRoute) {
125
- notFoundRoute.init({
126
- originalIndex: 99999999999,
127
- defaultSsr: this.options.defaultSsr
128
- });
129
- this.routesById[notFoundRoute.id] = notFoundRoute;
130
- }
131
- };
132
- this.subscribe = (eventType, fn) => {
133
- const listener = {
134
- eventType,
135
- fn
136
- };
137
- this.subscribers.add(listener);
138
- return () => {
139
- this.subscribers.delete(listener);
140
- };
141
- };
142
- this.emit = (routerEvent) => {
143
- this.subscribers.forEach((listener) => {
144
- if (listener.eventType === routerEvent.type) {
145
- listener.fn(routerEvent);
146
- }
147
- });
148
- };
149
- this.parseLocation = (previousLocation, locationToParse) => {
150
- const parse = ({
151
- pathname,
152
- search,
153
- hash,
154
- state
155
- }) => {
156
- const parsedSearch = this.options.parseSearch(search);
157
- const searchStr = this.options.stringifySearch(parsedSearch);
158
- return {
159
- pathname,
160
- searchStr,
161
- search: utils.replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.search, parsedSearch),
162
- hash: hash.split("#").reverse()[0] ?? "",
163
- href: `${pathname}${searchStr}${hash}`,
164
- state: utils.replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.state, state)
165
- };
166
- };
167
- const location = parse(locationToParse ?? this.history.location);
168
- const { __tempLocation, __tempKey } = location.state;
169
- if (__tempLocation && (!__tempKey || __tempKey === this.tempLocationKey)) {
170
- const parsedTempLocation = parse(__tempLocation);
171
- parsedTempLocation.state.key = location.state.key;
172
- delete parsedTempLocation.state.__tempLocation;
173
- return {
174
- ...parsedTempLocation,
175
- maskedLocation: location
176
- };
177
- }
178
- return location;
179
- };
180
- this.resolvePathWithBase = (from, path$1) => {
181
- const resolvedPath = path.resolvePath({
182
- basepath: this.basepath,
183
- base: from,
184
- to: path.cleanPath(path$1),
185
- trailingSlash: this.options.trailingSlash,
186
- caseSensitive: this.options.caseSensitive
187
- });
188
- return resolvedPath;
189
- };
190
- this.matchRoutes = (pathnameOrNext, locationSearchOrOpts, opts) => {
191
- if (typeof pathnameOrNext === "string") {
192
- return this.matchRoutesInternal(
193
- {
194
- pathname: pathnameOrNext,
195
- search: locationSearchOrOpts
196
- },
197
- opts
198
- );
199
- }
200
- return this.matchRoutesInternal(pathnameOrNext, locationSearchOrOpts);
201
- };
202
- this.getMatchedRoutes = (pathname, routePathname) => {
203
- return getMatchedRoutes({
204
- pathname,
205
- routePathname,
206
- basepath: this.basepath,
207
- caseSensitive: this.options.caseSensitive,
208
- routesByPath: this.routesByPath,
209
- routesById: this.routesById,
210
- flatRoutes: this.flatRoutes
211
- });
212
- };
213
- this.cancelMatch = (id) => {
214
- const match = this.getMatch(id);
215
- if (!match) return;
216
- match.abortController.abort();
217
- clearTimeout(match.pendingTimeout);
218
- };
219
- this.cancelMatches = () => {
220
- var _a;
221
- (_a = this.state.pendingMatches) == null ? void 0 : _a.forEach((match) => {
222
- this.cancelMatch(match.id);
223
- });
224
- };
225
- this.buildLocation = (opts) => {
226
- const build = (dest = {}) => {
227
- var _a;
228
- const currentLocation = dest._fromLocation || this.latestLocation;
229
- const allFromMatches = this.matchRoutes(currentLocation, {
230
- _buildLocation: true
231
- });
232
- const lastMatch = utils.last(allFromMatches);
233
- let fromPath = lastMatch.fullPath;
234
- if (dest.unsafeRelative === "path") {
235
- fromPath = currentLocation.pathname;
236
- } else if (dest.to && dest.from) {
237
- fromPath = dest.from;
238
- const existingFrom = [...allFromMatches].reverse().find((d) => {
239
- return d.fullPath === fromPath || d.fullPath === path.joinPaths([fromPath, "/"]);
240
- });
241
- if (!existingFrom) {
242
- console.warn(`Could not find match for from: ${dest.from}`);
243
- }
244
- }
245
- const fromSearch = lastMatch.search;
246
- const fromParams = { ...lastMatch.params };
247
- const nextTo = dest.to ? this.resolvePathWithBase(fromPath, `${dest.to}`) : fromPath;
248
- let nextParams = (dest.params ?? true) === true ? fromParams : {
249
- ...fromParams,
250
- ...utils.functionalUpdate(dest.params, fromParams)
251
- };
252
- const destRoutes = this.matchRoutes(
253
- nextTo,
254
- {},
255
- {
256
- _buildLocation: true
257
- }
258
- ).map((d) => this.looseRoutesById[d.routeId]);
259
- if (Object.keys(nextParams).length > 0) {
260
- destRoutes.map((route) => {
261
- var _a2;
262
- return ((_a2 = route.options.params) == null ? void 0 : _a2.stringify) ?? route.options.stringifyParams;
263
- }).filter(Boolean).forEach((fn) => {
264
- nextParams = { ...nextParams, ...fn(nextParams) };
265
- });
266
- }
267
- const nextPathname = path.interpolatePath({
268
- path: nextTo,
269
- params: nextParams ?? {},
270
- leaveWildcards: false,
271
- leaveParams: opts.leaveParams,
272
- decodeCharMap: this.pathParamsDecodeCharMap
273
- }).interpolatedPath;
274
- let nextSearch = fromSearch;
275
- if (opts._includeValidateSearch && ((_a = this.options.search) == null ? void 0 : _a.strict)) {
276
- let validatedSearch = {};
277
- destRoutes.forEach((route) => {
278
- try {
279
- if (route.options.validateSearch) {
280
- validatedSearch = {
281
- ...validatedSearch,
282
- ...validateSearch(route.options.validateSearch, {
283
- ...validatedSearch,
284
- ...nextSearch
285
- }) ?? {}
286
- };
287
- }
288
- } catch {
289
- }
290
- });
291
- nextSearch = validatedSearch;
292
- }
293
- nextSearch = applySearchMiddleware({
294
- search: nextSearch,
295
- dest,
296
- destRoutes,
297
- _includeValidateSearch: opts._includeValidateSearch
298
- });
299
- nextSearch = utils.replaceEqualDeep(fromSearch, nextSearch);
300
- const searchStr = this.options.stringifySearch(nextSearch);
301
- const hash = dest.hash === true ? currentLocation.hash : dest.hash ? utils.functionalUpdate(dest.hash, currentLocation.hash) : void 0;
302
- const hashStr = hash ? `#${hash}` : "";
303
- let nextState = dest.state === true ? currentLocation.state : dest.state ? utils.functionalUpdate(dest.state, currentLocation.state) : {};
304
- nextState = utils.replaceEqualDeep(currentLocation.state, nextState);
305
- return {
306
- pathname: nextPathname,
307
- search: nextSearch,
308
- searchStr,
309
- state: nextState,
310
- hash: hash ?? "",
311
- href: `${nextPathname}${searchStr}${hashStr}`,
312
- unmaskOnReload: dest.unmaskOnReload
313
- };
314
- };
315
- const buildWithMatches = (dest = {}, maskedDest) => {
316
- var _a;
317
- const next = build(dest);
318
- let maskedNext = maskedDest ? build(maskedDest) : void 0;
319
- if (!maskedNext) {
320
- let params = {};
321
- const foundMask = (_a = this.options.routeMasks) == null ? void 0 : _a.find((d) => {
322
- const match = path.matchPathname(this.basepath, next.pathname, {
323
- to: d.from,
324
- caseSensitive: false,
325
- fuzzy: false
326
- });
327
- if (match) {
328
- params = match;
329
- return true;
330
- }
331
- return false;
332
- });
333
- if (foundMask) {
334
- const { from: _from, ...maskProps } = foundMask;
335
- maskedDest = {
336
- ...utils.pick(opts, ["from"]),
337
- ...maskProps,
338
- params
339
- };
340
- maskedNext = build(maskedDest);
341
- }
342
- }
343
- if (maskedNext) {
344
- const maskedFinal = build(maskedDest);
345
- next.maskedLocation = maskedFinal;
346
- }
347
- return next;
348
- };
349
- if (opts.mask) {
350
- return buildWithMatches(opts, {
351
- ...utils.pick(opts, ["from"]),
352
- ...opts.mask
353
- });
354
- }
355
- return buildWithMatches(opts);
356
- };
357
- this.commitLocation = ({
358
- viewTransition,
359
- ignoreBlocker,
360
- ...next
361
- }) => {
362
- const isSameState = () => {
363
- const ignoredProps = [
364
- "key",
365
- "__TSR_index",
366
- "__hashScrollIntoViewOptions"
367
- ];
368
- ignoredProps.forEach((prop) => {
369
- next.state[prop] = this.latestLocation.state[prop];
370
- });
371
- const isEqual = utils.deepEqual(next.state, this.latestLocation.state);
372
- ignoredProps.forEach((prop) => {
373
- delete next.state[prop];
374
- });
375
- return isEqual;
376
- };
377
- const isSameUrl = this.latestLocation.href === next.href;
378
- const previousCommitPromise = this.commitLocationPromise;
379
- this.commitLocationPromise = utils.createControlledPromise(() => {
380
- previousCommitPromise == null ? void 0 : previousCommitPromise.resolve();
381
- });
382
- if (isSameUrl && isSameState()) {
383
- this.load();
384
- } else {
385
- let { maskedLocation, hashScrollIntoView, ...nextHistory } = next;
386
- if (maskedLocation) {
387
- nextHistory = {
388
- ...maskedLocation,
389
- state: {
390
- ...maskedLocation.state,
391
- __tempKey: void 0,
392
- __tempLocation: {
393
- ...nextHistory,
394
- search: nextHistory.searchStr,
395
- state: {
396
- ...nextHistory.state,
397
- __tempKey: void 0,
398
- __tempLocation: void 0,
399
- key: void 0
400
- }
401
- }
402
- }
403
- };
404
- if (nextHistory.unmaskOnReload ?? this.options.unmaskOnReload ?? false) {
405
- nextHistory.state.__tempKey = this.tempLocationKey;
406
- }
407
- }
408
- nextHistory.state.__hashScrollIntoViewOptions = hashScrollIntoView ?? this.options.defaultHashScrollIntoView ?? true;
409
- this.shouldViewTransition = viewTransition;
410
- this.history[next.replace ? "replace" : "push"](
411
- nextHistory.href,
412
- nextHistory.state,
413
- { ignoreBlocker }
414
- );
415
- }
416
- this.resetNextScroll = next.resetScroll ?? true;
417
- if (!this.history.subscribers.size) {
418
- this.load();
419
- }
420
- return this.commitLocationPromise;
421
- };
422
- this.buildAndCommitLocation = ({
423
- replace,
424
- resetScroll,
425
- hashScrollIntoView,
426
- viewTransition,
427
- ignoreBlocker,
428
- href,
429
- ...rest
430
- } = {}) => {
431
- if (href) {
432
- const currentIndex = this.history.location.state.__TSR_index;
433
- const parsed = history.parseHref(href, {
434
- __TSR_index: replace ? currentIndex : currentIndex + 1
435
- });
436
- rest.to = parsed.pathname;
437
- rest.search = this.options.parseSearch(parsed.search);
438
- rest.hash = parsed.hash.slice(1);
439
- }
440
- const location = this.buildLocation({
441
- ...rest,
442
- _includeValidateSearch: true
443
- });
444
- return this.commitLocation({
445
- ...location,
446
- viewTransition,
447
- replace,
448
- resetScroll,
449
- hashScrollIntoView,
450
- ignoreBlocker
451
- });
452
- };
453
- this.navigate = ({ to, reloadDocument, href, ...rest }) => {
454
- if (!reloadDocument && href) {
455
- try {
456
- new URL(`${href}`);
457
- reloadDocument = true;
458
- } catch {
459
- }
460
- }
461
- if (reloadDocument) {
462
- if (!href) {
463
- const location = this.buildLocation({ to, ...rest });
464
- href = this.history.createHref(location.href);
465
- }
466
- if (rest.replace) {
467
- window.location.replace(href);
468
- } else {
469
- window.location.href = href;
470
- }
471
- return;
472
- }
473
- return this.buildAndCommitLocation({
474
- ...rest,
475
- href,
476
- to
477
- });
478
- };
479
- this.beforeLoad = () => {
480
- this.cancelMatches();
481
- this.latestLocation = this.parseLocation(this.latestLocation);
482
- const pendingMatches = this.matchRoutes(this.latestLocation);
483
- this.__store.setState((s) => ({
484
- ...s,
485
- status: "pending",
486
- isLoading: true,
487
- location: this.latestLocation,
488
- pendingMatches,
489
- // If a cached moved to pendingMatches, remove it from cachedMatches
490
- cachedMatches: s.cachedMatches.filter((d) => {
491
- return !pendingMatches.find((e) => e.id === d.id);
492
- })
493
- }));
494
- };
495
- this.load = async (opts) => {
496
- let redirect$1;
497
- let notFound$1;
498
- let loadPromise;
499
- loadPromise = new Promise((resolve) => {
500
- this.startTransition(async () => {
501
- var _a;
502
- try {
503
- this.beforeLoad();
504
- const next = this.latestLocation;
505
- const prevLocation = this.state.resolvedLocation;
506
- if (!this.state.redirect) {
507
- this.emit({
508
- type: "onBeforeNavigate",
509
- ...getLocationChangeInfo({
510
- resolvedLocation: prevLocation,
511
- location: next
512
- })
513
- });
514
- }
515
- this.emit({
516
- type: "onBeforeLoad",
517
- ...getLocationChangeInfo({
518
- resolvedLocation: prevLocation,
519
- location: next
520
- })
521
- });
522
- await this.loadMatches({
523
- sync: opts == null ? void 0 : opts.sync,
524
- matches: this.state.pendingMatches,
525
- location: next,
526
- // eslint-disable-next-line @typescript-eslint/require-await
527
- onReady: async () => {
528
- this.startViewTransition(async () => {
529
- let exitingMatches;
530
- let enteringMatches;
531
- let stayingMatches;
532
- store.batch(() => {
533
- this.__store.setState((s) => {
534
- const previousMatches = s.matches;
535
- const newMatches = s.pendingMatches || s.matches;
536
- exitingMatches = previousMatches.filter(
537
- (match) => !newMatches.find((d) => d.id === match.id)
538
- );
539
- enteringMatches = newMatches.filter(
540
- (match) => !previousMatches.find((d) => d.id === match.id)
541
- );
542
- stayingMatches = previousMatches.filter(
543
- (match) => newMatches.find((d) => d.id === match.id)
544
- );
545
- return {
546
- ...s,
547
- isLoading: false,
548
- loadedAt: Date.now(),
549
- matches: newMatches,
550
- pendingMatches: void 0,
551
- cachedMatches: [
552
- ...s.cachedMatches,
553
- ...exitingMatches.filter((d) => d.status !== "error")
554
- ]
555
- };
556
- });
557
- this.clearExpiredCache();
558
- });
559
- [
560
- [exitingMatches, "onLeave"],
561
- [enteringMatches, "onEnter"],
562
- [stayingMatches, "onStay"]
563
- ].forEach(([matches, hook]) => {
564
- matches.forEach((match) => {
565
- var _a2, _b;
566
- (_b = (_a2 = this.looseRoutesById[match.routeId].options)[hook]) == null ? void 0 : _b.call(_a2, match);
567
- });
568
- });
569
- });
570
- }
571
- });
572
- } catch (err) {
573
- if (redirect.isRedirect(err)) {
574
- redirect$1 = err;
575
- if (!this.isServer) {
576
- this.navigate({
577
- ...redirect$1.options,
578
- replace: true,
579
- ignoreBlocker: true
580
- });
581
- }
582
- } else if (notFound.isNotFound(err)) {
583
- notFound$1 = err;
584
- }
585
- this.__store.setState((s) => ({
586
- ...s,
587
- statusCode: redirect$1 ? redirect$1.status : notFound$1 ? 404 : s.matches.some((d) => d.status === "error") ? 500 : 200,
588
- redirect: redirect$1
589
- }));
590
- }
591
- if (this.latestLoadPromise === loadPromise) {
592
- (_a = this.commitLocationPromise) == null ? void 0 : _a.resolve();
593
- this.latestLoadPromise = void 0;
594
- this.commitLocationPromise = void 0;
595
- }
596
- resolve();
597
- });
598
- });
599
- this.latestLoadPromise = loadPromise;
600
- await loadPromise;
601
- while (this.latestLoadPromise && loadPromise !== this.latestLoadPromise) {
602
- await this.latestLoadPromise;
603
- }
604
- if (this.hasNotFoundMatch()) {
605
- this.__store.setState((s) => ({
606
- ...s,
607
- statusCode: 404
608
- }));
609
- }
610
- };
611
- this.startViewTransition = (fn) => {
612
- const shouldViewTransition = this.shouldViewTransition ?? this.options.defaultViewTransition;
613
- delete this.shouldViewTransition;
614
- if (shouldViewTransition && typeof document !== "undefined" && "startViewTransition" in document && typeof document.startViewTransition === "function") {
615
- let startViewTransitionParams;
616
- if (typeof shouldViewTransition === "object" && this.isViewTransitionTypesSupported) {
617
- const next = this.latestLocation;
618
- const prevLocation = this.state.resolvedLocation;
619
- const resolvedViewTransitionTypes = typeof shouldViewTransition.types === "function" ? shouldViewTransition.types(
620
- getLocationChangeInfo({
621
- resolvedLocation: prevLocation,
622
- location: next
623
- })
624
- ) : shouldViewTransition.types;
625
- startViewTransitionParams = {
626
- update: fn,
627
- types: resolvedViewTransitionTypes
628
- };
629
- } else {
630
- startViewTransitionParams = fn;
631
- }
632
- document.startViewTransition(startViewTransitionParams);
633
- } else {
634
- fn();
635
- }
636
- };
637
- this.updateMatch = (id, updater) => {
638
- var _a;
639
- let updated;
640
- const isPending = (_a = this.state.pendingMatches) == null ? void 0 : _a.find((d) => d.id === id);
641
- const isMatched = this.state.matches.find((d) => d.id === id);
642
- const isCached = this.state.cachedMatches.find((d) => d.id === id);
643
- const matchesKey = isPending ? "pendingMatches" : isMatched ? "matches" : isCached ? "cachedMatches" : "";
644
- if (matchesKey) {
645
- this.__store.setState((s) => {
646
- var _a2;
647
- return {
648
- ...s,
649
- [matchesKey]: (_a2 = s[matchesKey]) == null ? void 0 : _a2.map(
650
- (d) => d.id === id ? updated = updater(d) : d
651
- )
652
- };
653
- });
654
- }
655
- return updated;
656
- };
657
- this.getMatch = (matchId) => {
658
- return [
659
- ...this.state.cachedMatches,
660
- ...this.state.pendingMatches ?? [],
661
- ...this.state.matches
662
- ].find((d) => d.id === matchId);
663
- };
664
- this.loadMatches = async ({
665
- location,
666
- matches,
667
- preload: allPreload,
668
- onReady,
669
- updateMatch = this.updateMatch,
670
- sync
671
- }) => {
672
- let firstBadMatchIndex;
673
- let rendered = false;
674
- const triggerOnReady = async () => {
675
- if (!rendered) {
676
- rendered = true;
677
- await (onReady == null ? void 0 : onReady());
678
- }
679
- };
680
- const resolvePreload = (matchId) => {
681
- return !!(allPreload && !this.state.matches.find((d) => d.id === matchId));
682
- };
683
- const handleRedirectAndNotFound = (match, err) => {
684
- var _a, _b, _c, _d;
685
- if (redirect.isRedirect(err) || notFound.isNotFound(err)) {
686
- if (redirect.isRedirect(err)) {
687
- if (err.redirectHandled) {
688
- if (!err.options.reloadDocument) {
689
- throw err;
690
- }
691
- }
692
- }
693
- (_a = match.beforeLoadPromise) == null ? void 0 : _a.resolve();
694
- (_b = match.loaderPromise) == null ? void 0 : _b.resolve();
695
- updateMatch(match.id, (prev) => ({
696
- ...prev,
697
- status: redirect.isRedirect(err) ? "redirected" : notFound.isNotFound(err) ? "notFound" : "error",
698
- isFetching: false,
699
- error: err,
700
- beforeLoadPromise: void 0,
701
- loaderPromise: void 0
702
- }));
703
- if (!err.routeId) {
704
- err.routeId = match.routeId;
705
- }
706
- (_c = match.loadPromise) == null ? void 0 : _c.resolve();
707
- if (redirect.isRedirect(err)) {
708
- rendered = true;
709
- err.options._fromLocation = location;
710
- err.redirectHandled = true;
711
- err = this.resolveRedirect(err);
712
- throw err;
713
- } else if (notFound.isNotFound(err)) {
714
- this._handleNotFound(matches, err, {
715
- updateMatch
716
- });
717
- (_d = this.serverSsr) == null ? void 0 : _d.onMatchSettled({
718
- router: this,
719
- match: this.getMatch(match.id)
720
- });
721
- throw err;
722
- }
723
- }
724
- };
725
- try {
726
- await new Promise((resolveAll, rejectAll) => {
727
- ;
728
- (async () => {
729
- var _a, _b, _c, _d;
730
- try {
731
- const handleSerialError = (index, err, routerCode) => {
732
- var _a2, _b2;
733
- const { id: matchId, routeId } = matches[index];
734
- const route = this.looseRoutesById[routeId];
735
- if (err instanceof Promise) {
736
- throw err;
737
- }
738
- err.routerCode = routerCode;
739
- firstBadMatchIndex = firstBadMatchIndex ?? index;
740
- handleRedirectAndNotFound(this.getMatch(matchId), err);
741
- try {
742
- (_b2 = (_a2 = route.options).onError) == null ? void 0 : _b2.call(_a2, err);
743
- } catch (errorHandlerErr) {
744
- err = errorHandlerErr;
745
- handleRedirectAndNotFound(this.getMatch(matchId), err);
746
- }
747
- updateMatch(matchId, (prev) => {
748
- var _a3, _b3;
749
- (_a3 = prev.beforeLoadPromise) == null ? void 0 : _a3.resolve();
750
- (_b3 = prev.loadPromise) == null ? void 0 : _b3.resolve();
751
- return {
752
- ...prev,
753
- error: err,
754
- status: "error",
755
- isFetching: false,
756
- updatedAt: Date.now(),
757
- abortController: new AbortController(),
758
- beforeLoadPromise: void 0
759
- };
760
- });
761
- };
762
- for (const [index, { id: matchId, routeId }] of matches.entries()) {
763
- const existingMatch = this.getMatch(matchId);
764
- const parentMatchId = (_a = matches[index - 1]) == null ? void 0 : _a.id;
765
- const route = this.looseRoutesById[routeId];
766
- const pendingMs = route.options.pendingMs ?? this.options.defaultPendingMs;
767
- const shouldPending = !!(onReady && !this.isServer && !resolvePreload(matchId) && (route.options.loader || route.options.beforeLoad || routeNeedsPreload(route)) && typeof pendingMs === "number" && pendingMs !== Infinity && (route.options.pendingComponent ?? ((_b = this.options) == null ? void 0 : _b.defaultPendingComponent)));
768
- let executeBeforeLoad = true;
769
- if (
770
- // If we are in the middle of a load, either of these will be present
771
- // (not to be confused with `loadPromise`, which is always defined)
772
- existingMatch.beforeLoadPromise || existingMatch.loaderPromise
773
- ) {
774
- if (shouldPending) {
775
- setTimeout(() => {
776
- try {
777
- triggerOnReady();
778
- } catch {
779
- }
780
- }, pendingMs);
781
- }
782
- console.log(`Match ${matchId} is already loading`, {
783
- match: this.getMatch(matchId)
784
- });
785
- await existingMatch.beforeLoadPromise;
786
- executeBeforeLoad = this.getMatch(matchId).status === "error";
787
- }
788
- if (executeBeforeLoad) {
789
- try {
790
- updateMatch(matchId, (prev) => {
791
- const prevLoadPromise = prev.loadPromise;
792
- return {
793
- ...prev,
794
- loadPromise: utils.createControlledPromise(() => {
795
- prevLoadPromise == null ? void 0 : prevLoadPromise.resolve();
796
- }),
797
- beforeLoadPromise: utils.createControlledPromise()
798
- };
799
- });
800
- const abortController = new AbortController();
801
- let pendingTimeout;
802
- if (shouldPending) {
803
- pendingTimeout = setTimeout(() => {
804
- try {
805
- triggerOnReady();
806
- } catch {
807
- }
808
- }, pendingMs);
809
- }
810
- const { paramsError, searchError } = this.getMatch(matchId);
811
- if (paramsError) {
812
- handleSerialError(index, paramsError, "PARSE_PARAMS");
813
- }
814
- if (searchError) {
815
- handleSerialError(index, searchError, "VALIDATE_SEARCH");
816
- }
817
- const getParentMatchContext = () => parentMatchId ? this.getMatch(parentMatchId).context : this.options.context ?? {};
818
- updateMatch(matchId, (prev) => ({
819
- ...prev,
820
- isFetching: "beforeLoad",
821
- fetchCount: prev.fetchCount + 1,
822
- abortController,
823
- pendingTimeout,
824
- context: {
825
- ...getParentMatchContext(),
826
- ...prev.__routeContext
827
- }
828
- }));
829
- const { search, params, context, cause } = this.getMatch(matchId);
830
- const preload = resolvePreload(matchId);
831
- const beforeLoadFnContext = {
832
- search,
833
- abortController,
834
- params,
835
- preload,
836
- context,
837
- location,
838
- navigate: (opts) => this.navigate({ ...opts, _fromLocation: location }),
839
- buildLocation: this.buildLocation,
840
- cause: preload ? "preload" : cause,
841
- matches
842
- };
843
- const beforeLoadContext = await ((_d = (_c = route.options).beforeLoad) == null ? void 0 : _d.call(_c, beforeLoadFnContext)) ?? {};
844
- if (redirect.isRedirect(beforeLoadContext) || notFound.isNotFound(beforeLoadContext)) {
845
- handleSerialError(index, beforeLoadContext, "BEFORE_LOAD");
846
- }
847
- updateMatch(matchId, (prev) => {
848
- return {
849
- ...prev,
850
- __beforeLoadContext: beforeLoadContext,
851
- context: {
852
- ...getParentMatchContext(),
853
- ...prev.__routeContext,
854
- ...beforeLoadContext
855
- },
856
- abortController
857
- };
858
- });
859
- } catch (err) {
860
- handleSerialError(index, err, "BEFORE_LOAD");
861
- }
862
- updateMatch(matchId, (prev) => {
863
- var _a2;
864
- (_a2 = prev.beforeLoadPromise) == null ? void 0 : _a2.resolve();
865
- return {
866
- ...prev,
867
- beforeLoadPromise: void 0,
868
- isFetching: false
869
- };
870
- });
871
- }
872
- }
873
- const validResolvedMatches = matches.slice(0, firstBadMatchIndex);
874
- const matchPromises = [];
875
- validResolvedMatches.forEach(({ id: matchId, routeId }, index) => {
876
- matchPromises.push(
877
- (async () => {
878
- const { loaderPromise: prevLoaderPromise } = this.getMatch(matchId);
879
- let loaderShouldRunAsync = false;
880
- let loaderIsRunningAsync = false;
881
- if (prevLoaderPromise) {
882
- await prevLoaderPromise;
883
- const match = this.getMatch(matchId);
884
- if (match.error) {
885
- handleRedirectAndNotFound(match, match.error);
886
- }
887
- } else {
888
- const parentMatchPromise = matchPromises[index - 1];
889
- const route = this.looseRoutesById[routeId];
890
- const getLoaderContext = () => {
891
- const {
892
- params,
893
- loaderDeps,
894
- abortController,
895
- context,
896
- cause
897
- } = this.getMatch(matchId);
898
- const preload2 = resolvePreload(matchId);
899
- return {
900
- params,
901
- deps: loaderDeps,
902
- preload: !!preload2,
903
- parentMatchPromise,
904
- abortController,
905
- context,
906
- location,
907
- navigate: (opts) => this.navigate({ ...opts, _fromLocation: location }),
908
- cause: preload2 ? "preload" : cause,
909
- route
910
- };
911
- };
912
- const age = Date.now() - this.getMatch(matchId).updatedAt;
913
- const preload = resolvePreload(matchId);
914
- const staleAge = preload ? route.options.preloadStaleTime ?? this.options.defaultPreloadStaleTime ?? 3e4 : route.options.staleTime ?? this.options.defaultStaleTime ?? 0;
915
- const shouldReloadOption = route.options.shouldReload;
916
- const shouldReload = typeof shouldReloadOption === "function" ? shouldReloadOption(getLoaderContext()) : shouldReloadOption;
917
- updateMatch(matchId, (prev) => ({
918
- ...prev,
919
- loaderPromise: utils.createControlledPromise(),
920
- preload: !!preload && !this.state.matches.find((d) => d.id === matchId)
921
- }));
922
- const executeHead = async () => {
923
- var _a2, _b2, _c2, _d2, _e, _f;
924
- const match = this.getMatch(matchId);
925
- if (!match) {
926
- return;
927
- }
928
- const assetContext = {
929
- matches,
930
- match,
931
- params: match.params,
932
- loaderData: match.loaderData
933
- };
934
- const headFnContent = await ((_b2 = (_a2 = route.options).head) == null ? void 0 : _b2.call(_a2, assetContext));
935
- const meta = headFnContent == null ? void 0 : headFnContent.meta;
936
- const links = headFnContent == null ? void 0 : headFnContent.links;
937
- const headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
938
- const scripts = await ((_d2 = (_c2 = route.options).scripts) == null ? void 0 : _d2.call(_c2, assetContext));
939
- const headers = await ((_f = (_e = route.options).headers) == null ? void 0 : _f.call(_e, assetContext));
940
- return { meta, links, headScripts, headers, scripts };
941
- };
942
- const runLoader = async () => {
943
- var _a2, _b2, _c2, _d2, _e;
944
- try {
945
- const potentialPendingMinPromise = async () => {
946
- const latestMatch = this.getMatch(matchId);
947
- if (latestMatch.minPendingPromise) {
948
- await latestMatch.minPendingPromise;
949
- }
950
- };
951
- try {
952
- this.loadRouteChunk(route);
953
- updateMatch(matchId, (prev) => ({
954
- ...prev,
955
- isFetching: "loader"
956
- }));
957
- const loaderData = await ((_b2 = (_a2 = route.options).loader) == null ? void 0 : _b2.call(_a2, getLoaderContext()));
958
- handleRedirectAndNotFound(
959
- this.getMatch(matchId),
960
- loaderData
961
- );
962
- await route._lazyPromise;
963
- await potentialPendingMinPromise();
964
- await route._componentsPromise;
965
- updateMatch(matchId, (prev) => ({
966
- ...prev,
967
- error: void 0,
968
- status: "success",
969
- isFetching: false,
970
- updatedAt: Date.now(),
971
- loaderData
972
- }));
973
- const head = await executeHead();
974
- updateMatch(matchId, (prev) => ({
975
- ...prev,
976
- ...head
977
- }));
978
- } catch (e) {
979
- let error = e;
980
- await potentialPendingMinPromise();
981
- handleRedirectAndNotFound(this.getMatch(matchId), e);
982
- try {
983
- (_d2 = (_c2 = route.options).onError) == null ? void 0 : _d2.call(_c2, e);
984
- } catch (onErrorError) {
985
- error = onErrorError;
986
- handleRedirectAndNotFound(
987
- this.getMatch(matchId),
988
- onErrorError
989
- );
990
- }
991
- const head = await executeHead();
992
- updateMatch(matchId, (prev) => ({
993
- ...prev,
994
- error,
995
- status: "error",
996
- isFetching: false,
997
- ...head
998
- }));
999
- }
1000
- (_e = this.serverSsr) == null ? void 0 : _e.onMatchSettled({
1001
- router: this,
1002
- match: this.getMatch(matchId)
1003
- });
1004
- } catch (err) {
1005
- const head = await executeHead();
1006
- updateMatch(matchId, (prev) => ({
1007
- ...prev,
1008
- loaderPromise: void 0,
1009
- ...head
1010
- }));
1011
- handleRedirectAndNotFound(this.getMatch(matchId), err);
1012
- }
1013
- };
1014
- const { status, invalid } = this.getMatch(matchId);
1015
- loaderShouldRunAsync = status === "success" && (invalid || (shouldReload ?? age > staleAge));
1016
- if (preload && route.options.preload === false) {
1017
- } else if (loaderShouldRunAsync && !sync) {
1018
- loaderIsRunningAsync = true;
1019
- (async () => {
1020
- try {
1021
- await runLoader();
1022
- const { loaderPromise, loadPromise } = this.getMatch(matchId);
1023
- loaderPromise == null ? void 0 : loaderPromise.resolve();
1024
- loadPromise == null ? void 0 : loadPromise.resolve();
1025
- updateMatch(matchId, (prev) => ({
1026
- ...prev,
1027
- loaderPromise: void 0
1028
- }));
1029
- } catch (err) {
1030
- if (redirect.isRedirect(err)) {
1031
- await this.navigate(err.options);
1032
- }
1033
- }
1034
- })();
1035
- } else if (status !== "success" || loaderShouldRunAsync && sync) {
1036
- await runLoader();
1037
- } else {
1038
- const head = await executeHead();
1039
- updateMatch(matchId, (prev) => ({
1040
- ...prev,
1041
- ...head
1042
- }));
1043
- }
1044
- }
1045
- if (!loaderIsRunningAsync) {
1046
- const { loaderPromise, loadPromise } = this.getMatch(matchId);
1047
- loaderPromise == null ? void 0 : loaderPromise.resolve();
1048
- loadPromise == null ? void 0 : loadPromise.resolve();
1049
- }
1050
- updateMatch(matchId, (prev) => ({
1051
- ...prev,
1052
- isFetching: loaderIsRunningAsync ? prev.isFetching : false,
1053
- loaderPromise: loaderIsRunningAsync ? prev.loaderPromise : void 0,
1054
- invalid: false
1055
- }));
1056
- return this.getMatch(matchId);
1057
- })()
1058
- );
1059
- });
1060
- await Promise.all(matchPromises);
1061
- resolveAll();
1062
- } catch (err) {
1063
- rejectAll(err);
1064
- }
1065
- })();
1066
- });
1067
- await triggerOnReady();
1068
- } catch (err) {
1069
- if (redirect.isRedirect(err) || notFound.isNotFound(err)) {
1070
- if (notFound.isNotFound(err) && !allPreload) {
1071
- await triggerOnReady();
1072
- }
1073
- throw err;
1074
- }
1075
- }
1076
- return matches;
1077
- };
1078
- this.invalidate = (opts) => {
1079
- const invalidate = (d) => {
1080
- var _a;
1081
- if (((_a = opts == null ? void 0 : opts.filter) == null ? void 0 : _a.call(opts, d)) ?? true) {
1082
- return {
1083
- ...d,
1084
- invalid: true,
1085
- ...d.status === "error" ? { status: "pending", error: void 0 } : {}
1086
- };
1087
- }
1088
- return d;
1089
- };
1090
- this.__store.setState((s) => {
1091
- var _a;
1092
- return {
1093
- ...s,
1094
- matches: s.matches.map(invalidate),
1095
- cachedMatches: s.cachedMatches.map(invalidate),
1096
- pendingMatches: (_a = s.pendingMatches) == null ? void 0 : _a.map(invalidate)
1097
- };
1098
- });
1099
- this.shouldViewTransition = false;
1100
- return this.load({ sync: opts == null ? void 0 : opts.sync });
1101
- };
1102
- this.resolveRedirect = (redirect2) => {
1103
- if (!redirect2.options.href) {
1104
- redirect2.options.href = this.buildLocation(redirect2.options).href;
1105
- redirect2.headers.set("Location", redirect2.options.href);
1106
- }
1107
- if (!redirect2.headers.get("Location")) {
1108
- redirect2.headers.set("Location", redirect2.options.href);
1109
- }
1110
- return redirect2;
1111
- };
1112
- this.clearCache = (opts) => {
1113
- const filter = opts == null ? void 0 : opts.filter;
1114
- if (filter !== void 0) {
1115
- this.__store.setState((s) => {
1116
- return {
1117
- ...s,
1118
- cachedMatches: s.cachedMatches.filter(
1119
- (m) => !filter(m)
1120
- )
1121
- };
1122
- });
1123
- } else {
1124
- this.__store.setState((s) => {
1125
- return {
1126
- ...s,
1127
- cachedMatches: []
1128
- };
1129
- });
1130
- }
1131
- };
1132
- this.clearExpiredCache = () => {
1133
- const filter = (d) => {
1134
- const route = this.looseRoutesById[d.routeId];
1135
- if (!route.options.loader) {
1136
- return true;
1137
- }
1138
- const gcTime = (d.preload ? route.options.preloadGcTime ?? this.options.defaultPreloadGcTime : route.options.gcTime ?? this.options.defaultGcTime) ?? 5 * 60 * 1e3;
1139
- return !(d.status !== "error" && Date.now() - d.updatedAt < gcTime);
1140
- };
1141
- this.clearCache({ filter });
1142
- };
1143
- this.loadRouteChunk = (route) => {
1144
- if (route._lazyPromise === void 0) {
1145
- if (route.lazyFn) {
1146
- route._lazyPromise = route.lazyFn().then((lazyRoute) => {
1147
- const { id: _id, ...options2 } = lazyRoute.options;
1148
- Object.assign(route.options, options2);
1149
- });
1150
- } else {
1151
- route._lazyPromise = Promise.resolve();
1152
- }
1153
- }
1154
- if (route._componentsPromise === void 0) {
1155
- route._componentsPromise = route._lazyPromise.then(
1156
- () => Promise.all(
1157
- componentTypes.map(async (type) => {
1158
- const component = route.options[type];
1159
- if (component == null ? void 0 : component.preload) {
1160
- await component.preload();
1161
- }
1162
- })
1163
- )
1164
- );
1165
- }
1166
- return route._componentsPromise;
1167
- };
1168
- this.preloadRoute = async (opts) => {
1169
- const next = this.buildLocation(opts);
1170
- let matches = this.matchRoutes(next, {
1171
- throwOnError: true,
1172
- preload: true,
1173
- dest: opts
1174
- });
1175
- const activeMatchIds = new Set(
1176
- [...this.state.matches, ...this.state.pendingMatches ?? []].map(
1177
- (d) => d.id
1178
- )
1179
- );
1180
- const loadedMatchIds = /* @__PURE__ */ new Set([
1181
- ...activeMatchIds,
1182
- ...this.state.cachedMatches.map((d) => d.id)
1183
- ]);
1184
- store.batch(() => {
1185
- matches.forEach((match) => {
1186
- if (!loadedMatchIds.has(match.id)) {
1187
- this.__store.setState((s) => ({
1188
- ...s,
1189
- cachedMatches: [...s.cachedMatches, match]
1190
- }));
1191
- }
1192
- });
1193
- });
1194
- try {
1195
- matches = await this.loadMatches({
1196
- matches,
1197
- location: next,
1198
- preload: true,
1199
- updateMatch: (id, updater) => {
1200
- if (activeMatchIds.has(id)) {
1201
- matches = matches.map((d) => d.id === id ? updater(d) : d);
1202
- } else {
1203
- this.updateMatch(id, updater);
1204
- }
1205
- }
1206
- });
1207
- return matches;
1208
- } catch (err) {
1209
- if (redirect.isRedirect(err)) {
1210
- if (err.options.reloadDocument) {
1211
- return void 0;
1212
- }
1213
- return await this.preloadRoute({
1214
- ...err.options,
1215
- _fromLocation: next
1216
- });
1217
- }
1218
- if (!notFound.isNotFound(err)) {
1219
- console.error(err);
1220
- }
1221
- return void 0;
1222
- }
1223
- };
1224
- this.matchRoute = (location, opts) => {
1225
- const matchLocation = {
1226
- ...location,
1227
- to: location.to ? this.resolvePathWithBase(
1228
- location.from || "",
1229
- location.to
1230
- ) : void 0,
1231
- params: location.params || {},
1232
- leaveParams: true
1233
- };
1234
- const next = this.buildLocation(matchLocation);
1235
- if ((opts == null ? void 0 : opts.pending) && this.state.status !== "pending") {
1236
- return false;
1237
- }
1238
- const pending = (opts == null ? void 0 : opts.pending) === void 0 ? !this.state.isLoading : opts.pending;
1239
- const baseLocation = pending ? this.latestLocation : this.state.resolvedLocation || this.state.location;
1240
- const match = path.matchPathname(this.basepath, baseLocation.pathname, {
1241
- ...opts,
1242
- to: next.pathname
1243
- });
1244
- if (!match) {
1245
- return false;
1246
- }
1247
- if (location.params) {
1248
- if (!utils.deepEqual(match, location.params, { partial: true })) {
1249
- return false;
1250
- }
1251
- }
1252
- if (match && ((opts == null ? void 0 : opts.includeSearch) ?? true)) {
1253
- return utils.deepEqual(baseLocation.search, next.search, { partial: true }) ? match : false;
1254
- }
1255
- return match;
1256
- };
1257
- this._handleNotFound = (matches, err, {
1258
- updateMatch = this.updateMatch
1259
- } = {}) => {
1260
- var _a;
1261
- const routeCursor = this.routesById[err.routeId ?? ""] ?? this.routeTree;
1262
- const matchesByRouteId = {};
1263
- for (const match of matches) {
1264
- matchesByRouteId[match.routeId] = match;
1265
- }
1266
- if (!routeCursor.options.notFoundComponent && ((_a = this.options) == null ? void 0 : _a.defaultNotFoundComponent)) {
1267
- routeCursor.options.notFoundComponent = this.options.defaultNotFoundComponent;
1268
- }
1269
- invariant(
1270
- routeCursor.options.notFoundComponent,
1271
- "No notFoundComponent found. Please set a notFoundComponent on your route or provide a defaultNotFoundComponent to the router."
1272
- );
1273
- const matchForRoute = matchesByRouteId[routeCursor.id];
1274
- invariant(
1275
- matchForRoute,
1276
- "Could not find match for route: " + routeCursor.id
1277
- );
1278
- updateMatch(matchForRoute.id, (prev) => ({
1279
- ...prev,
1280
- status: "notFound",
1281
- error: err,
1282
- isFetching: false
1283
- }));
1284
- if (err.routerCode === "BEFORE_LOAD" && routeCursor.parentRoute) {
1285
- err.routeId = routeCursor.parentRoute.id;
1286
- this._handleNotFound(matches, err, {
1287
- updateMatch
1288
- });
1289
- }
1290
- };
1291
- this.hasNotFoundMatch = () => {
1292
- return this.__store.state.matches.some(
1293
- (d) => d.status === "notFound" || d.globalNotFound
1294
- );
1295
- };
1296
- this.update({
1297
- defaultPreloadDelay: 50,
1298
- defaultPendingMs: 1e3,
1299
- defaultPendingMinMs: 500,
1300
- context: void 0,
1301
- ...options,
1302
- caseSensitive: options.caseSensitive ?? false,
1303
- notFoundMode: options.notFoundMode ?? "fuzzy",
1304
- stringifySearch: options.stringifySearch ?? searchParams.defaultStringifySearch,
1305
- parseSearch: options.parseSearch ?? searchParams.defaultParseSearch
1306
- });
1307
- if (typeof document !== "undefined") {
1308
- window.__TSR_ROUTER__ = this;
1309
- }
1310
- }
1311
- get state() {
1312
- return this.__store.state;
1313
- }
1314
- get looseRoutesById() {
1315
- return this.routesById;
1316
- }
1317
- matchRoutesInternal(next, opts) {
1318
- var _a;
1319
- const { foundRoute, matchedRoutes, routeParams } = this.getMatchedRoutes(
1320
- next.pathname,
1321
- (_a = opts == null ? void 0 : opts.dest) == null ? void 0 : _a.to
1322
- );
1323
- let isGlobalNotFound = false;
1324
- if (
1325
- // If we found a route, and it's not an index route and we have left over path
1326
- foundRoute ? foundRoute.path !== "/" && routeParams["**"] : (
1327
- // Or if we didn't find a route and we have left over path
1328
- path.trimPathRight(next.pathname)
1329
- )
1330
- ) {
1331
- if (this.options.notFoundRoute) {
1332
- matchedRoutes.push(this.options.notFoundRoute);
1333
- } else {
1334
- isGlobalNotFound = true;
1335
- }
1336
- }
1337
- const globalNotFoundRouteId = (() => {
1338
- if (!isGlobalNotFound) {
1339
- return void 0;
1340
- }
1341
- if (this.options.notFoundMode !== "root") {
1342
- for (let i = matchedRoutes.length - 1; i >= 0; i--) {
1343
- const route = matchedRoutes[i];
1344
- if (route.children) {
1345
- return route.id;
1346
- }
1347
- }
1348
- }
1349
- return root.rootRouteId;
1350
- })();
1351
- const parseErrors = matchedRoutes.map((route) => {
1352
- var _a2;
1353
- let parsedParamsError;
1354
- const parseParams = ((_a2 = route.options.params) == null ? void 0 : _a2.parse) ?? route.options.parseParams;
1355
- if (parseParams) {
1356
- try {
1357
- const parsedParams = parseParams(routeParams);
1358
- Object.assign(routeParams, parsedParams);
1359
- } catch (err) {
1360
- parsedParamsError = new PathParamError(err.message, {
1361
- cause: err
1362
- });
1363
- if (opts == null ? void 0 : opts.throwOnError) {
1364
- throw parsedParamsError;
1365
- }
1366
- return parsedParamsError;
1367
- }
1368
- }
1369
- return;
1370
- });
1371
- const matches = [];
1372
- const getParentContext = (parentMatch) => {
1373
- const parentMatchId = parentMatch == null ? void 0 : parentMatch.id;
1374
- const parentContext = !parentMatchId ? this.options.context ?? {} : parentMatch.context ?? this.options.context ?? {};
1375
- return parentContext;
1376
- };
1377
- matchedRoutes.forEach((route, index) => {
1378
- var _a2, _b;
1379
- const parentMatch = matches[index - 1];
1380
- const [preMatchSearch, strictMatchSearch, searchError] = (() => {
1381
- const parentSearch = (parentMatch == null ? void 0 : parentMatch.search) ?? next.search;
1382
- const parentStrictSearch = (parentMatch == null ? void 0 : parentMatch._strictSearch) ?? {};
1383
- try {
1384
- const strictSearch = validateSearch(route.options.validateSearch, { ...parentSearch }) ?? {};
1385
- return [
1386
- {
1387
- ...parentSearch,
1388
- ...strictSearch
1389
- },
1390
- { ...parentStrictSearch, ...strictSearch },
1391
- void 0
1392
- ];
1393
- } catch (err) {
1394
- let searchParamError = err;
1395
- if (!(err instanceof SearchParamError)) {
1396
- searchParamError = new SearchParamError(err.message, {
1397
- cause: err
1398
- });
1399
- }
1400
- if (opts == null ? void 0 : opts.throwOnError) {
1401
- throw searchParamError;
1402
- }
1403
- return [parentSearch, {}, searchParamError];
1404
- }
1405
- })();
1406
- const loaderDeps = ((_b = (_a2 = route.options).loaderDeps) == null ? void 0 : _b.call(_a2, {
1407
- search: preMatchSearch
1408
- })) ?? "";
1409
- const loaderDepsHash = loaderDeps ? JSON.stringify(loaderDeps) : "";
1410
- const { usedParams, interpolatedPath } = path.interpolatePath({
1411
- path: route.fullPath,
1412
- params: routeParams,
1413
- decodeCharMap: this.pathParamsDecodeCharMap
1414
- });
1415
- const matchId = path.interpolatePath({
1416
- path: route.id,
1417
- params: routeParams,
1418
- leaveWildcards: true,
1419
- decodeCharMap: this.pathParamsDecodeCharMap
1420
- }).interpolatedPath + loaderDepsHash;
1421
- const existingMatch = this.getMatch(matchId);
1422
- const previousMatch = this.state.matches.find(
1423
- (d) => d.routeId === route.id
1424
- );
1425
- const cause = previousMatch ? "stay" : "enter";
1426
- let match;
1427
- if (existingMatch) {
1428
- match = {
1429
- ...existingMatch,
1430
- cause,
1431
- params: previousMatch ? utils.replaceEqualDeep(previousMatch.params, routeParams) : routeParams,
1432
- _strictParams: usedParams,
1433
- search: previousMatch ? utils.replaceEqualDeep(previousMatch.search, preMatchSearch) : utils.replaceEqualDeep(existingMatch.search, preMatchSearch),
1434
- _strictSearch: strictMatchSearch
1435
- };
1436
- } else {
1437
- const status = route.options.loader || route.options.beforeLoad || route.lazyFn || routeNeedsPreload(route) ? "pending" : "success";
1438
- match = {
1439
- id: matchId,
1440
- index,
1441
- routeId: route.id,
1442
- params: previousMatch ? utils.replaceEqualDeep(previousMatch.params, routeParams) : routeParams,
1443
- _strictParams: usedParams,
1444
- pathname: path.joinPaths([this.basepath, interpolatedPath]),
1445
- updatedAt: Date.now(),
1446
- search: previousMatch ? utils.replaceEqualDeep(previousMatch.search, preMatchSearch) : preMatchSearch,
1447
- _strictSearch: strictMatchSearch,
1448
- searchError: void 0,
1449
- status,
1450
- isFetching: false,
1451
- error: void 0,
1452
- paramsError: parseErrors[index],
1453
- __routeContext: {},
1454
- __beforeLoadContext: {},
1455
- context: {},
1456
- abortController: new AbortController(),
1457
- fetchCount: 0,
1458
- cause,
1459
- loaderDeps: previousMatch ? utils.replaceEqualDeep(previousMatch.loaderDeps, loaderDeps) : loaderDeps,
1460
- invalid: false,
1461
- preload: false,
1462
- links: void 0,
1463
- scripts: void 0,
1464
- headScripts: void 0,
1465
- meta: void 0,
1466
- staticData: route.options.staticData || {},
1467
- loadPromise: utils.createControlledPromise(),
1468
- fullPath: route.fullPath
1469
- };
1470
- }
1471
- if (!(opts == null ? void 0 : opts.preload)) {
1472
- match.globalNotFound = globalNotFoundRouteId === route.id;
1473
- }
1474
- match.searchError = searchError;
1475
- const parentContext = getParentContext(parentMatch);
1476
- match.context = {
1477
- ...parentContext,
1478
- ...match.__routeContext,
1479
- ...match.__beforeLoadContext
1480
- };
1481
- matches.push(match);
1482
- });
1483
- matches.forEach((match, index) => {
1484
- var _a2, _b;
1485
- const route = this.looseRoutesById[match.routeId];
1486
- const existingMatch = this.getMatch(match.id);
1487
- if (!existingMatch && (opts == null ? void 0 : opts._buildLocation) !== true) {
1488
- const parentMatch = matches[index - 1];
1489
- const parentContext = getParentContext(parentMatch);
1490
- const contextFnContext = {
1491
- deps: match.loaderDeps,
1492
- params: match.params,
1493
- context: parentContext,
1494
- location: next,
1495
- navigate: (opts2) => this.navigate({ ...opts2, _fromLocation: next }),
1496
- buildLocation: this.buildLocation,
1497
- cause: match.cause,
1498
- abortController: match.abortController,
1499
- preload: !!match.preload,
1500
- matches
1501
- };
1502
- match.__routeContext = ((_b = (_a2 = route.options).context) == null ? void 0 : _b.call(_a2, contextFnContext)) ?? {};
1503
- match.context = {
1504
- ...parentContext,
1505
- ...match.__routeContext,
1506
- ...match.__beforeLoadContext
1507
- };
1508
- }
1509
- });
1510
- return matches;
1511
- }
1512
- }
1513
- class SearchParamError extends Error {
1514
- }
1515
- class PathParamError extends Error {
1516
- }
1517
- function lazyFn(fn, key) {
1518
- return async (...args) => {
1519
- const imported = await fn();
1520
- return imported[key || "default"](...args);
1521
- };
1522
- }
1523
- function getInitialRouterState(location) {
1524
- return {
1525
- loadedAt: 0,
1526
- isLoading: false,
1527
- isTransitioning: false,
1528
- status: "idle",
1529
- resolvedLocation: void 0,
1530
- location,
1531
- matches: [],
1532
- pendingMatches: [],
1533
- cachedMatches: [],
1534
- statusCode: 200
1535
- };
1536
- }
1537
- function validateSearch(validateSearch2, input) {
1538
- if (validateSearch2 == null) return {};
1539
- if ("~standard" in validateSearch2) {
1540
- const result = validateSearch2["~standard"].validate(input);
1541
- if (result instanceof Promise)
1542
- throw new SearchParamError("Async validation not supported");
1543
- if (result.issues)
1544
- throw new SearchParamError(JSON.stringify(result.issues, void 0, 2), {
1545
- cause: result
1546
- });
1547
- return result.value;
1548
- }
1549
- if ("parse" in validateSearch2) {
1550
- return validateSearch2.parse(input);
1551
- }
1552
- if (typeof validateSearch2 === "function") {
1553
- return validateSearch2(input);
1554
- }
1555
- return {};
1556
- }
1557
- const componentTypes = [
1558
- "component",
1559
- "errorComponent",
1560
- "pendingComponent",
1561
- "notFoundComponent"
1562
- ];
1563
- function routeNeedsPreload(route) {
1564
- var _a;
1565
- for (const componentType of componentTypes) {
1566
- if ((_a = route.options[componentType]) == null ? void 0 : _a.preload) {
1567
- return true;
1568
- }
1569
- }
1570
- return false;
1571
- }
1572
- function processRouteTree({
1573
- routeTree,
1574
- initRoute
1575
- }) {
1576
- const routesById = {};
1577
- const routesByPath = {};
1578
- const recurseRoutes = (childRoutes) => {
1579
- childRoutes.forEach((childRoute, i) => {
1580
- initRoute == null ? void 0 : initRoute(childRoute, i);
1581
- const existingRoute = routesById[childRoute.id];
1582
- invariant(
1583
- !existingRoute,
1584
- `Duplicate routes found with id: ${String(childRoute.id)}`
1585
- );
1586
- routesById[childRoute.id] = childRoute;
1587
- if (!childRoute.isRoot && childRoute.path) {
1588
- const trimmedFullPath = path.trimPathRight(childRoute.fullPath);
1589
- if (!routesByPath[trimmedFullPath] || childRoute.fullPath.endsWith("/")) {
1590
- routesByPath[trimmedFullPath] = childRoute;
1591
- }
1592
- }
1593
- const children = childRoute.children;
1594
- if (children == null ? void 0 : children.length) {
1595
- recurseRoutes(children);
1596
- }
1597
- });
1598
- };
1599
- recurseRoutes([routeTree]);
1600
- const scoredRoutes = [];
1601
- const routes = Object.values(routesById);
1602
- routes.forEach((d, i) => {
1603
- var _a;
1604
- if (d.isRoot || !d.path) {
1605
- return;
1606
- }
1607
- const trimmed = path.trimPathLeft(d.fullPath);
1608
- const parsed = path.parsePathname(trimmed);
1609
- while (parsed.length > 1 && ((_a = parsed[0]) == null ? void 0 : _a.value) === "/") {
1610
- parsed.shift();
1611
- }
1612
- const scores = parsed.map((segment) => {
1613
- if (segment.value === "/") {
1614
- return 0.75;
1615
- }
1616
- if (segment.type === "param" && segment.prefixSegment && segment.suffixSegment) {
1617
- return 0.55;
1618
- }
1619
- if (segment.type === "param" && segment.prefixSegment) {
1620
- return 0.52;
1621
- }
1622
- if (segment.type === "param" && segment.suffixSegment) {
1623
- return 0.51;
1624
- }
1625
- if (segment.type === "param") {
1626
- return 0.5;
1627
- }
1628
- if (segment.type === "wildcard" && segment.prefixSegment && segment.suffixSegment) {
1629
- return 0.3;
1630
- }
1631
- if (segment.type === "wildcard" && segment.prefixSegment) {
1632
- return 0.27;
1633
- }
1634
- if (segment.type === "wildcard" && segment.suffixSegment) {
1635
- return 0.26;
1636
- }
1637
- if (segment.type === "wildcard") {
1638
- return 0.25;
1639
- }
1640
- return 1;
1641
- });
1642
- scoredRoutes.push({ child: d, trimmed, parsed, index: i, scores });
1643
- });
1644
- const flatRoutes = scoredRoutes.sort((a, b) => {
1645
- const minLength = Math.min(a.scores.length, b.scores.length);
1646
- for (let i = 0; i < minLength; i++) {
1647
- if (a.scores[i] !== b.scores[i]) {
1648
- return b.scores[i] - a.scores[i];
1649
- }
1650
- }
1651
- if (a.scores.length !== b.scores.length) {
1652
- return b.scores.length - a.scores.length;
1653
- }
1654
- for (let i = 0; i < minLength; i++) {
1655
- if (a.parsed[i].value !== b.parsed[i].value) {
1656
- return a.parsed[i].value > b.parsed[i].value ? 1 : -1;
1657
- }
1658
- }
1659
- return a.index - b.index;
1660
- }).map((d, i) => {
1661
- d.child.rank = i;
1662
- return d.child;
1663
- });
1664
- return { routesById, routesByPath, flatRoutes };
1665
- }
1666
- function getMatchedRoutes({
1667
- pathname,
1668
- routePathname,
1669
- basepath,
1670
- caseSensitive,
1671
- routesByPath,
1672
- routesById,
1673
- flatRoutes
1674
- }) {
1675
- let routeParams = {};
1676
- const trimmedPath = path.trimPathRight(pathname);
1677
- const getMatchedParams = (route) => {
1678
- var _a;
1679
- const result = path.matchPathname(basepath, trimmedPath, {
1680
- to: route.fullPath,
1681
- caseSensitive: ((_a = route.options) == null ? void 0 : _a.caseSensitive) ?? caseSensitive,
1682
- fuzzy: true
1683
- });
1684
- return result;
1685
- };
1686
- let foundRoute = routePathname !== void 0 ? routesByPath[routePathname] : void 0;
1687
- if (foundRoute) {
1688
- routeParams = getMatchedParams(foundRoute);
1689
- } else {
1690
- foundRoute = flatRoutes.find((route) => {
1691
- const matchedParams = getMatchedParams(route);
1692
- if (matchedParams) {
1693
- routeParams = matchedParams;
1694
- return true;
1695
- }
1696
- return false;
1697
- });
1698
- }
1699
- let routeCursor = foundRoute || routesById[root.rootRouteId];
1700
- const matchedRoutes = [routeCursor];
1701
- while (routeCursor.parentRoute) {
1702
- routeCursor = routeCursor.parentRoute;
1703
- matchedRoutes.unshift(routeCursor);
1704
- }
1705
- return { matchedRoutes, routeParams, foundRoute };
1706
- }
1707
- function applySearchMiddleware({
1708
- search,
1709
- dest,
1710
- destRoutes,
1711
- _includeValidateSearch
1712
- }) {
1713
- const allMiddlewares = destRoutes.reduce(
1714
- (acc, route) => {
1715
- var _a;
1716
- const middlewares = [];
1717
- if ("search" in route.options) {
1718
- if ((_a = route.options.search) == null ? void 0 : _a.middlewares) {
1719
- middlewares.push(...route.options.search.middlewares);
1720
- }
1721
- } else if (route.options.preSearchFilters || route.options.postSearchFilters) {
1722
- const legacyMiddleware = ({
1723
- search: search2,
1724
- next
1725
- }) => {
1726
- let nextSearch = search2;
1727
- if ("preSearchFilters" in route.options && route.options.preSearchFilters) {
1728
- nextSearch = route.options.preSearchFilters.reduce(
1729
- (prev, next2) => next2(prev),
1730
- search2
1731
- );
1732
- }
1733
- const result = next(nextSearch);
1734
- if ("postSearchFilters" in route.options && route.options.postSearchFilters) {
1735
- return route.options.postSearchFilters.reduce(
1736
- (prev, next2) => next2(prev),
1737
- result
1738
- );
1739
- }
1740
- return result;
1741
- };
1742
- middlewares.push(legacyMiddleware);
1743
- }
1744
- if (_includeValidateSearch && route.options.validateSearch) {
1745
- const validate = ({ search: search2, next }) => {
1746
- const result = next(search2);
1747
- try {
1748
- const validatedSearch = {
1749
- ...result,
1750
- ...validateSearch(route.options.validateSearch, result) ?? {}
1751
- };
1752
- return validatedSearch;
1753
- } catch {
1754
- return result;
1755
- }
1756
- };
1757
- middlewares.push(validate);
1758
- }
1759
- return acc.concat(middlewares);
1760
- },
1761
- []
1762
- ) ?? [];
1763
- const final = ({ search: search2 }) => {
1764
- if (!dest.search) {
1765
- return {};
1766
- }
1767
- if (dest.search === true) {
1768
- return search2;
1769
- }
1770
- return utils.functionalUpdate(dest.search, search2);
1771
- };
1772
- allMiddlewares.push(final);
1773
- const applyNext = (index, currentSearch) => {
1774
- if (index >= allMiddlewares.length) {
1775
- return currentSearch;
1776
- }
1777
- const middleware = allMiddlewares[index];
1778
- const next = (newSearch) => {
1779
- return applyNext(index + 1, newSearch);
1780
- };
1781
- return middleware({ search: currentSearch, next });
1782
- };
1783
- return applyNext(0, search);
1784
- }
1785
- exports.PathParamError = PathParamError;
1786
- exports.RouterCore = RouterCore;
1787
- exports.SearchParamError = SearchParamError;
1788
- exports.componentTypes = componentTypes;
1789
- exports.defaultSerializeError = defaultSerializeError;
1790
- exports.getInitialRouterState = getInitialRouterState;
1791
- exports.getLocationChangeInfo = getLocationChangeInfo;
1792
- exports.getMatchedRoutes = getMatchedRoutes;
1793
- exports.lazyFn = lazyFn;
1794
- exports.processRouteTree = processRouteTree;
1795
- //# sourceMappingURL=router.cjs.map