@tanstack/react-router 0.0.1-beta.26 → 0.0.1-beta.260

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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/build/cjs/CatchBoundary.js +128 -0
  3. package/build/cjs/CatchBoundary.js.map +1 -0
  4. package/build/cjs/Matches.js +244 -0
  5. package/build/cjs/Matches.js.map +1 -0
  6. package/build/cjs/RouterProvider.js +166 -0
  7. package/build/cjs/RouterProvider.js.map +1 -0
  8. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +2 -22
  9. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  10. package/build/cjs/awaited.js +43 -0
  11. package/build/cjs/awaited.js.map +1 -0
  12. package/build/cjs/defer.js +37 -0
  13. package/build/cjs/defer.js.map +1 -0
  14. package/build/cjs/fileRoute.js +27 -0
  15. package/build/cjs/fileRoute.js.map +1 -0
  16. package/build/cjs/index.js +125 -0
  17. package/build/cjs/index.js.map +1 -0
  18. package/build/cjs/lazyRouteComponent.js +54 -0
  19. package/build/cjs/lazyRouteComponent.js.map +1 -0
  20. package/build/cjs/link.js +149 -0
  21. package/build/cjs/link.js.map +1 -0
  22. package/build/cjs/path.js +214 -0
  23. package/build/cjs/path.js.map +1 -0
  24. package/build/cjs/qss.js +63 -0
  25. package/build/cjs/qss.js.map +1 -0
  26. package/build/cjs/redirects.js +28 -0
  27. package/build/cjs/redirects.js.map +1 -0
  28. package/build/cjs/route.js +140 -0
  29. package/build/cjs/route.js.map +1 -0
  30. package/build/cjs/router.js +1143 -0
  31. package/build/cjs/router.js.map +1 -0
  32. package/build/cjs/scroll-restoration.js +202 -0
  33. package/build/cjs/scroll-restoration.js.map +1 -0
  34. package/build/cjs/searchParams.js +81 -0
  35. package/build/cjs/searchParams.js.map +1 -0
  36. package/build/cjs/useBlocker.js +55 -0
  37. package/build/cjs/useBlocker.js.map +1 -0
  38. package/build/cjs/useNavigate.js +75 -0
  39. package/build/cjs/useNavigate.js.map +1 -0
  40. package/build/cjs/useParams.js +26 -0
  41. package/build/cjs/useParams.js.map +1 -0
  42. package/build/cjs/useSearch.js +25 -0
  43. package/build/cjs/useSearch.js.map +1 -0
  44. package/build/cjs/utils.js +239 -0
  45. package/build/cjs/utils.js.map +1 -0
  46. package/build/esm/index.js +2213 -2529
  47. package/build/esm/index.js.map +1 -1
  48. package/build/stats-html.html +3498 -2694
  49. package/build/stats-react.json +1210 -44
  50. package/build/types/CatchBoundary.d.ts +36 -0
  51. package/build/types/Matches.d.ts +57 -0
  52. package/build/types/RouterProvider.d.ts +36 -0
  53. package/build/types/awaited.d.ts +9 -0
  54. package/build/types/defer.d.ts +19 -0
  55. package/build/types/fileRoute.d.ts +34 -0
  56. package/build/types/history.d.ts +7 -0
  57. package/build/types/index.d.ts +27 -114
  58. package/build/types/injectHtml.d.ts +0 -0
  59. package/build/types/lazyRouteComponent.d.ts +2 -0
  60. package/build/types/link.d.ts +105 -0
  61. package/build/types/location.d.ts +14 -0
  62. package/build/types/path.d.ts +17 -0
  63. package/build/types/qss.d.ts +2 -0
  64. package/build/types/redirects.d.ts +11 -0
  65. package/build/types/route.d.ts +279 -0
  66. package/build/types/routeInfo.d.ts +22 -0
  67. package/build/types/router.d.ts +183 -0
  68. package/build/types/scroll-restoration.d.ts +18 -0
  69. package/build/types/searchParams.d.ts +7 -0
  70. package/build/types/useBlocker.d.ts +8 -0
  71. package/build/types/useNavigate.d.ts +20 -0
  72. package/build/types/useParams.d.ts +7 -0
  73. package/build/types/useSearch.d.ts +7 -0
  74. package/build/types/utils.d.ts +66 -0
  75. package/build/umd/index.development.js +2793 -2481
  76. package/build/umd/index.development.js.map +1 -1
  77. package/build/umd/index.production.js +4 -4
  78. package/build/umd/index.production.js.map +1 -1
  79. package/package.json +11 -10
  80. package/src/CatchBoundary.tsx +101 -0
  81. package/src/Matches.tsx +428 -0
  82. package/src/RouterProvider.tsx +254 -0
  83. package/src/awaited.tsx +40 -0
  84. package/src/defer.ts +55 -0
  85. package/src/fileRoute.ts +154 -0
  86. package/src/history.ts +8 -0
  87. package/src/index.tsx +28 -714
  88. package/src/injectHtml.ts +28 -0
  89. package/src/lazyRouteComponent.tsx +33 -0
  90. package/src/link.tsx +509 -0
  91. package/src/location.ts +15 -0
  92. package/src/path.ts +261 -0
  93. package/src/qss.ts +53 -0
  94. package/src/redirects.ts +39 -0
  95. package/src/route.ts +915 -0
  96. package/src/routeInfo.ts +68 -0
  97. package/src/router.ts +1748 -0
  98. package/src/scroll-restoration.tsx +230 -0
  99. package/src/searchParams.ts +79 -0
  100. package/src/useBlocker.tsx +26 -0
  101. package/src/useNavigate.tsx +110 -0
  102. package/src/useParams.tsx +25 -0
  103. package/src/useSearch.tsx +25 -0
  104. package/src/utils.ts +350 -0
  105. package/build/cjs/react-router/src/index.js +0 -473
  106. package/build/cjs/react-router/src/index.js.map +0 -1
  107. package/build/cjs/router-core/build/esm/index.js +0 -2530
  108. package/build/cjs/router-core/build/esm/index.js.map +0 -1
@@ -0,0 +1,1143 @@
1
+ /**
2
+ * @tanstack/react-router/src/index.tsx
3
+ *
4
+ * Copyright (c) TanStack
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ 'use strict';
12
+
13
+ var history = require('@tanstack/history');
14
+ var store = require('@tanstack/store');
15
+ var searchParams = require('./searchParams.js');
16
+ var utils = require('./utils.js');
17
+ var RouterProvider = require('./RouterProvider.js');
18
+ var path = require('./path.js');
19
+ var invariant = require('tiny-invariant');
20
+ var redirects = require('./redirects.js');
21
+
22
+ // import warning from 'tiny-warning'
23
+
24
+ //
25
+
26
+ const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
27
+ const preloadWarning = 'Error preloading route! ☝️';
28
+ class Router {
29
+ // Option-independent properties
30
+ tempLocationKey = `${Math.round(Math.random() * 10000000)}`;
31
+ resetNextScroll = true;
32
+ navigateTimeout = null;
33
+ latestLoadPromise = Promise.resolve();
34
+ subscribers = new Set();
35
+ pendingMatches = [];
36
+ injectedHtml = [];
37
+
38
+ // Must build in constructor
39
+
40
+ constructor(options) {
41
+ this.update({
42
+ defaultPreloadDelay: 50,
43
+ defaultPendingMs: 1000,
44
+ defaultPendingMinMs: 500,
45
+ context: undefined,
46
+ ...options,
47
+ stringifySearch: options?.stringifySearch ?? searchParams.defaultStringifySearch,
48
+ parseSearch: options?.parseSearch ?? searchParams.defaultParseSearch
49
+ });
50
+ }
51
+
52
+ // These are default implementations that can optionally be overridden
53
+ // by the router provider once rendered. We provide these so that the
54
+ // router can be used in a non-react environment if necessary
55
+ startReactTransition = fn => fn();
56
+ update = newOptions => {
57
+ this.options = {
58
+ ...this.options,
59
+ ...newOptions
60
+ };
61
+ this.basepath = `/${path.trimPath(newOptions.basepath ?? '') ?? ''}`;
62
+ if (!this.history || this.options.history && this.options.history !== this.history) {
63
+ this.history = this.options.history ?? (typeof document !== 'undefined' ? history.createBrowserHistory() : history.createMemoryHistory());
64
+ this.latestLocation = this.parseLocation();
65
+ }
66
+ if (this.options.routeTree !== this.routeTree) {
67
+ this.routeTree = this.options.routeTree;
68
+ this.buildRouteTree();
69
+ }
70
+ if (!this.__store) {
71
+ this.__store = new store.Store(getInitialRouterState(this.latestLocation), {
72
+ onUpdate: () => {
73
+ this.__store.state = {
74
+ ...this.state,
75
+ status: this.state.isTransitioning || this.state.isLoading ? 'pending' : 'idle'
76
+ };
77
+ }
78
+ });
79
+ }
80
+ };
81
+ get state() {
82
+ return this.__store.state;
83
+ }
84
+ buildRouteTree = () => {
85
+ this.routesById = {};
86
+ this.routesByPath = {};
87
+ const notFoundRoute = this.options.notFoundRoute;
88
+ if (notFoundRoute) {
89
+ notFoundRoute.init({
90
+ originalIndex: 99999999999
91
+ });
92
+ this.routesById[notFoundRoute.id] = notFoundRoute;
93
+ }
94
+ const recurseRoutes = childRoutes => {
95
+ childRoutes.forEach((childRoute, i) => {
96
+ childRoute.init({
97
+ originalIndex: i
98
+ });
99
+ const existingRoute = this.routesById[childRoute.id];
100
+ invariant(!existingRoute, `Duplicate routes found with id: ${String(childRoute.id)}`);
101
+ this.routesById[childRoute.id] = childRoute;
102
+ if (!childRoute.isRoot && childRoute.path) {
103
+ const trimmedFullPath = path.trimPathRight(childRoute.fullPath);
104
+ if (!this.routesByPath[trimmedFullPath] || childRoute.fullPath.endsWith('/')) {
105
+ this.routesByPath[trimmedFullPath] = childRoute;
106
+ }
107
+ }
108
+ const children = childRoute.children;
109
+ if (children?.length) {
110
+ recurseRoutes(children);
111
+ }
112
+ });
113
+ };
114
+ recurseRoutes([this.routeTree]);
115
+ const scoredRoutes = [];
116
+ Object.values(this.routesById).forEach((d, i) => {
117
+ if (d.isRoot || !d.path) {
118
+ return;
119
+ }
120
+ const trimmed = path.trimPathLeft(d.fullPath);
121
+ const parsed = path.parsePathname(trimmed);
122
+ while (parsed.length > 1 && parsed[0]?.value === '/') {
123
+ parsed.shift();
124
+ }
125
+ const score = parsed.map(d => {
126
+ if (d.type === 'param') {
127
+ return 0.5;
128
+ }
129
+ if (d.type === 'wildcard') {
130
+ return 0.25;
131
+ }
132
+ return 1;
133
+ });
134
+ scoredRoutes.push({
135
+ child: d,
136
+ trimmed,
137
+ parsed,
138
+ index: i,
139
+ score
140
+ });
141
+ });
142
+ this.flatRoutes = scoredRoutes.sort((a, b) => {
143
+ let isIndex = a.trimmed === '/' ? 1 : b.trimmed === '/' ? -1 : 0;
144
+ if (isIndex !== 0) return isIndex;
145
+ const length = Math.min(a.score.length, b.score.length);
146
+
147
+ // Sort by length of score
148
+ if (a.score.length !== b.score.length) {
149
+ return b.score.length - a.score.length;
150
+ }
151
+
152
+ // Sort by min available score
153
+ for (let i = 0; i < length; i++) {
154
+ if (a.score[i] !== b.score[i]) {
155
+ return b.score[i] - a.score[i];
156
+ }
157
+ }
158
+
159
+ // Sort by min available parsed value
160
+ for (let i = 0; i < length; i++) {
161
+ if (a.parsed[i].value !== b.parsed[i].value) {
162
+ return a.parsed[i].value > b.parsed[i].value ? 1 : -1;
163
+ }
164
+ }
165
+
166
+ // Sort by length of trimmed full path
167
+ if (a.trimmed !== b.trimmed) {
168
+ return a.trimmed > b.trimmed ? 1 : -1;
169
+ }
170
+
171
+ // Sort by original index
172
+ return a.index - b.index;
173
+ }).map((d, i) => {
174
+ d.child.rank = i;
175
+ return d.child;
176
+ });
177
+ };
178
+ subscribe = (eventType, fn) => {
179
+ const listener = {
180
+ eventType,
181
+ fn
182
+ };
183
+ this.subscribers.add(listener);
184
+ return () => {
185
+ this.subscribers.delete(listener);
186
+ };
187
+ };
188
+ emit = routerEvent => {
189
+ this.subscribers.forEach(listener => {
190
+ if (listener.eventType === routerEvent.type) {
191
+ listener.fn(routerEvent);
192
+ }
193
+ });
194
+ };
195
+ checkLatest = promise => {
196
+ return this.latestLoadPromise !== promise ? this.latestLoadPromise : undefined;
197
+ };
198
+ parseLocation = previousLocation => {
199
+ const parse = ({
200
+ pathname,
201
+ search,
202
+ hash,
203
+ state
204
+ }) => {
205
+ const parsedSearch = this.options.parseSearch(search);
206
+ return {
207
+ pathname: pathname,
208
+ searchStr: search,
209
+ search: utils.replaceEqualDeep(previousLocation?.search, parsedSearch),
210
+ hash: hash.split('#').reverse()[0] ?? '',
211
+ href: `${pathname}${search}${hash}`,
212
+ state: utils.replaceEqualDeep(previousLocation?.state, state)
213
+ };
214
+ };
215
+ const location = parse(this.history.location);
216
+ let {
217
+ __tempLocation,
218
+ __tempKey
219
+ } = location.state;
220
+ if (__tempLocation && (!__tempKey || __tempKey === this.tempLocationKey)) {
221
+ // Sync up the location keys
222
+ const parsedTempLocation = parse(__tempLocation);
223
+ parsedTempLocation.state.key = location.state.key;
224
+ delete parsedTempLocation.state.__tempLocation;
225
+ return {
226
+ ...parsedTempLocation,
227
+ maskedLocation: location
228
+ };
229
+ }
230
+ return location;
231
+ };
232
+ resolvePathWithBase = (from, path$1) => {
233
+ return path.resolvePath(this.basepath, from, path.cleanPath(path$1));
234
+ };
235
+ get looseRoutesById() {
236
+ return this.routesById;
237
+ }
238
+ matchRoutes = (pathname, locationSearch, opts) => {
239
+ let routeParams = {};
240
+ let foundRoute = this.flatRoutes.find(route => {
241
+ const matchedParams = path.matchPathname(this.basepath, path.trimPathRight(pathname), {
242
+ to: route.fullPath,
243
+ caseSensitive: route.options.caseSensitive ?? this.options.caseSensitive,
244
+ fuzzy: true
245
+ });
246
+ if (matchedParams) {
247
+ routeParams = matchedParams;
248
+ return true;
249
+ }
250
+ return false;
251
+ });
252
+ let routeCursor = foundRoute || this.routesById['__root__'];
253
+ let matchedRoutes = [routeCursor];
254
+
255
+ // Check to see if the route needs a 404 entry
256
+ if (
257
+ // If we found a route, and it's not an index route and we have left over path
258
+ (foundRoute ? foundRoute.path !== '/' && routeParams['**'] :
259
+ // Or if we didn't find a route and we have left over path
260
+ path.trimPathRight(pathname)) &&
261
+ // And we have a 404 route configured
262
+ this.options.notFoundRoute) {
263
+ matchedRoutes.push(this.options.notFoundRoute);
264
+ }
265
+ while (routeCursor?.parentRoute) {
266
+ routeCursor = routeCursor.parentRoute;
267
+ if (routeCursor) matchedRoutes.unshift(routeCursor);
268
+ }
269
+
270
+ // Existing matches are matches that are already loaded along with
271
+ // pending matches that are still loading
272
+
273
+ const parseErrors = matchedRoutes.map(route => {
274
+ let parsedParamsError;
275
+ if (route.options.parseParams) {
276
+ try {
277
+ const parsedParams = route.options.parseParams(routeParams);
278
+ // Add the parsed params to the accumulated params bag
279
+ Object.assign(routeParams, parsedParams);
280
+ } catch (err) {
281
+ parsedParamsError = new PathParamError(err.message, {
282
+ cause: err
283
+ });
284
+ if (opts?.throwOnError) {
285
+ throw parsedParamsError;
286
+ }
287
+ return parsedParamsError;
288
+ }
289
+ }
290
+ return;
291
+ });
292
+ const matches = [];
293
+ matchedRoutes.forEach((route, index) => {
294
+ // Take each matched route and resolve + validate its search params
295
+ // This has to happen serially because each route's search params
296
+ // can depend on the parent route's search params
297
+ // It must also happen before we create the match so that we can
298
+ // pass the search params to the route's potential key function
299
+ // which is used to uniquely identify the route match in state
300
+
301
+ const parentMatch = matches[index - 1];
302
+ const [preMatchSearch, searchError] = (() => {
303
+ // Validate the search params and stabilize them
304
+ const parentSearch = parentMatch?.search ?? locationSearch;
305
+ try {
306
+ const validator = typeof route.options.validateSearch === 'object' ? route.options.validateSearch.parse : route.options.validateSearch;
307
+ let search = validator?.(parentSearch) ?? {};
308
+ return [{
309
+ ...parentSearch,
310
+ ...search
311
+ }, undefined];
312
+ } catch (err) {
313
+ const searchError = new SearchParamError(err.message, {
314
+ cause: err
315
+ });
316
+ if (opts?.throwOnError) {
317
+ throw searchError;
318
+ }
319
+ return [parentSearch, searchError];
320
+ }
321
+ })();
322
+ const interpolatedPath = path.interpolatePath(route.fullPath, routeParams);
323
+ const matchId = path.interpolatePath(route.id, routeParams, true) + (route.options.key?.({
324
+ search: preMatchSearch,
325
+ location: this.state.location
326
+ }) ?? '');
327
+
328
+ // Waste not, want not. If we already have a match for this route,
329
+ // reuse it. This is important for layout routes, which might stick
330
+ // around between navigation actions that only change leaf routes.
331
+ const existingMatch = RouterProvider.getRouteMatch(this.state, matchId);
332
+ const cause = this.state.matches.find(d => d.id === matchId) ? 'stay' : 'enter';
333
+
334
+ // Create a fresh route match
335
+ const hasLoaders = !!(route.options.loader || componentTypes.some(d => route.options[d]?.preload));
336
+ const match = existingMatch ? {
337
+ ...existingMatch,
338
+ cause
339
+ } : {
340
+ id: matchId,
341
+ routeId: route.id,
342
+ params: routeParams,
343
+ pathname: path.joinPaths([this.basepath, interpolatedPath]),
344
+ updatedAt: Date.now(),
345
+ search: {},
346
+ searchError: undefined,
347
+ status: hasLoaders ? 'pending' : 'success',
348
+ showPending: false,
349
+ isFetching: false,
350
+ invalid: false,
351
+ error: undefined,
352
+ paramsError: parseErrors[index],
353
+ loadPromise: Promise.resolve(),
354
+ context: undefined,
355
+ abortController: new AbortController(),
356
+ shouldReloadDeps: undefined,
357
+ fetchedAt: 0,
358
+ cause
359
+ };
360
+
361
+ // Regardless of whether we're reusing an existing match or creating
362
+ // a new one, we need to update the match's search params
363
+ match.search = utils.replaceEqualDeep(match.search, preMatchSearch);
364
+ // And also update the searchError if there is one
365
+ match.searchError = searchError;
366
+ matches.push(match);
367
+ });
368
+ return matches;
369
+ };
370
+ cancelMatch = id => {
371
+ RouterProvider.getRouteMatch(this.state, id)?.abortController?.abort();
372
+ };
373
+ cancelMatches = () => {
374
+ this.state.pendingMatches?.forEach(match => {
375
+ this.cancelMatch(match.id);
376
+ });
377
+ };
378
+ buildLocation = opts => {
379
+ const build = (dest = {}, matches) => {
380
+ const from = this.latestLocation;
381
+ const fromSearch = (this.state.pendingMatches || this.state.matches).at(-1)?.search || from.search;
382
+ const fromPathname = dest.from ?? from.pathname;
383
+ let pathname = this.resolvePathWithBase(fromPathname, `${dest.to ?? ''}`);
384
+ const fromMatches = this.matchRoutes(fromPathname, fromSearch);
385
+ const stayingMatches = matches?.filter(d => fromMatches?.find(e => e.routeId === d.routeId));
386
+ const prevParams = {
387
+ ...utils.last(fromMatches)?.params
388
+ };
389
+ let nextParams = (dest.params ?? true) === true ? prevParams : utils.functionalUpdate(dest.params, prevParams);
390
+ if (nextParams) {
391
+ matches?.map(d => this.looseRoutesById[d.routeId].options.stringifyParams).filter(Boolean).forEach(fn => {
392
+ nextParams = {
393
+ ...nextParams,
394
+ ...fn(nextParams)
395
+ };
396
+ });
397
+ }
398
+ pathname = path.interpolatePath(pathname, nextParams ?? {});
399
+ const preSearchFilters = stayingMatches?.map(match => this.looseRoutesById[match.routeId].options.preSearchFilters ?? []).flat().filter(Boolean) ?? [];
400
+ const postSearchFilters = stayingMatches?.map(match => this.looseRoutesById[match.routeId].options.postSearchFilters ?? []).flat().filter(Boolean) ?? [];
401
+
402
+ // Pre filters first
403
+ const preFilteredSearch = preSearchFilters?.length ? preSearchFilters?.reduce((prev, next) => next(prev), fromSearch) : fromSearch;
404
+
405
+ // Then the link/navigate function
406
+ const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
407
+ : dest.search ? utils.functionalUpdate(dest.search, preFilteredSearch) ?? {} // Updater
408
+ : preSearchFilters?.length ? preFilteredSearch // Preserve resolvedFrom filters
409
+ : {};
410
+
411
+ // Then post filters
412
+ const postFilteredSearch = postSearchFilters?.length ? postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
413
+ const search = utils.replaceEqualDeep(fromSearch, postFilteredSearch);
414
+ const searchStr = this.options.stringifySearch(search);
415
+ const hash = dest.hash === true ? from.hash : dest.hash ? utils.functionalUpdate(dest.hash, from.hash) : from.hash;
416
+ const hashStr = hash ? `#${hash}` : '';
417
+ let nextState = dest.state === true ? from.state : dest.state ? utils.functionalUpdate(dest.state, from.state) : from.state;
418
+ nextState = utils.replaceEqualDeep(from.state, nextState);
419
+ return {
420
+ pathname,
421
+ search,
422
+ searchStr,
423
+ state: nextState,
424
+ hash,
425
+ href: `${pathname}${searchStr}${hashStr}`,
426
+ unmaskOnReload: dest.unmaskOnReload
427
+ };
428
+ };
429
+ const buildWithMatches = (dest = {}, maskedDest) => {
430
+ let next = build(dest);
431
+ let maskedNext = maskedDest ? build(maskedDest) : undefined;
432
+ if (!maskedNext) {
433
+ let params = {};
434
+ let foundMask = this.options.routeMasks?.find(d => {
435
+ const match = path.matchPathname(this.basepath, next.pathname, {
436
+ to: d.from,
437
+ caseSensitive: false,
438
+ fuzzy: false
439
+ });
440
+ if (match) {
441
+ params = match;
442
+ return true;
443
+ }
444
+ return false;
445
+ });
446
+ if (foundMask) {
447
+ foundMask = {
448
+ ...foundMask,
449
+ from: path.interpolatePath(foundMask.from, params)
450
+ };
451
+ maskedDest = foundMask;
452
+ maskedNext = build(maskedDest);
453
+ }
454
+ }
455
+ const nextMatches = this.matchRoutes(next.pathname, next.search);
456
+ const maskedMatches = maskedNext ? this.matchRoutes(maskedNext.pathname, maskedNext.search) : undefined;
457
+ const maskedFinal = maskedNext ? build(maskedDest, maskedMatches) : undefined;
458
+ const final = build(dest, nextMatches);
459
+ if (maskedFinal) {
460
+ final.maskedLocation = maskedFinal;
461
+ }
462
+ return final;
463
+ };
464
+ if (opts.mask) {
465
+ return buildWithMatches(opts, {
466
+ ...utils.pick(opts, ['from']),
467
+ ...opts.mask
468
+ });
469
+ }
470
+ return buildWithMatches(opts);
471
+ };
472
+ commitLocation = async ({
473
+ startTransition,
474
+ ...next
475
+ }) => {
476
+ if (this.navigateTimeout) clearTimeout(this.navigateTimeout);
477
+ const isSameUrl = this.latestLocation.href === next.href;
478
+
479
+ // If the next urls are the same and we're not replacing,
480
+ // do nothing
481
+ if (!isSameUrl || !next.replace) {
482
+ let {
483
+ maskedLocation,
484
+ ...nextHistory
485
+ } = next;
486
+ if (maskedLocation) {
487
+ nextHistory = {
488
+ ...maskedLocation,
489
+ state: {
490
+ ...maskedLocation.state,
491
+ __tempKey: undefined,
492
+ __tempLocation: {
493
+ ...nextHistory,
494
+ search: nextHistory.searchStr,
495
+ state: {
496
+ ...nextHistory.state,
497
+ __tempKey: undefined,
498
+ __tempLocation: undefined,
499
+ key: undefined
500
+ }
501
+ }
502
+ }
503
+ };
504
+ if (nextHistory.unmaskOnReload ?? this.options.unmaskOnReload ?? false) {
505
+ nextHistory.state.__tempKey = this.tempLocationKey;
506
+ }
507
+ }
508
+ const apply = () => {
509
+ this.history[next.replace ? 'replace' : 'push'](nextHistory.href, nextHistory.state);
510
+ };
511
+ if (startTransition ?? true) {
512
+ this.startReactTransition(apply);
513
+ } else {
514
+ apply();
515
+ }
516
+ }
517
+ this.resetNextScroll = next.resetScroll ?? true;
518
+ return this.latestLoadPromise;
519
+ };
520
+ buildAndCommitLocation = ({
521
+ replace,
522
+ resetScroll,
523
+ startTransition,
524
+ ...rest
525
+ } = {}) => {
526
+ const location = this.buildLocation(rest);
527
+ return this.commitLocation({
528
+ ...location,
529
+ startTransition,
530
+ replace,
531
+ resetScroll
532
+ });
533
+ };
534
+ navigate = ({
535
+ from,
536
+ to = '',
537
+ ...rest
538
+ }) => {
539
+ // If this link simply reloads the current route,
540
+ // make sure it has a new key so it will trigger a data refresh
541
+
542
+ // If this `to` is a valid external URL, return
543
+ // null for LinkUtils
544
+ const toString = String(to);
545
+ const fromString = typeof from === 'undefined' ? from : String(from);
546
+ let isExternal;
547
+ try {
548
+ new URL(`${toString}`);
549
+ isExternal = true;
550
+ } catch (e) {}
551
+ invariant(!isExternal, 'Attempting to navigate to external url with this.navigate!');
552
+ return this.buildAndCommitLocation({
553
+ ...rest,
554
+ from: fromString,
555
+ to: toString
556
+ });
557
+ };
558
+ loadMatches = async ({
559
+ checkLatest,
560
+ matches,
561
+ preload,
562
+ invalidate
563
+ }) => {
564
+ let latestPromise;
565
+ let firstBadMatchIndex;
566
+ const updatePendingMatch = match => {
567
+ this.__store.setState(s => ({
568
+ ...s,
569
+ pendingMatches: s.pendingMatches?.map(d => d.id === match.id ? match : d)
570
+ }));
571
+ };
572
+ const abortController = new AbortController();
573
+
574
+ // Check each match middleware to see if the route can be accessed
575
+ try {
576
+ for (let [index, match] of matches.entries()) {
577
+ const parentMatch = matches[index - 1];
578
+ const route = this.looseRoutesById[match.routeId];
579
+ const handleErrorAndRedirect = (err, code) => {
580
+ err.routerCode = code;
581
+ firstBadMatchIndex = firstBadMatchIndex ?? index;
582
+ if (redirects.isRedirect(err)) {
583
+ throw err;
584
+ }
585
+ try {
586
+ route.options.onError?.(err);
587
+ } catch (errorHandlerErr) {
588
+ err = errorHandlerErr;
589
+ if (redirects.isRedirect(errorHandlerErr)) {
590
+ throw errorHandlerErr;
591
+ }
592
+ }
593
+ matches[index] = match = {
594
+ ...match,
595
+ error: err,
596
+ status: 'error',
597
+ updatedAt: Date.now(),
598
+ abortController
599
+ };
600
+ };
601
+ try {
602
+ if (match.paramsError) {
603
+ handleErrorAndRedirect(match.paramsError, 'PARSE_PARAMS');
604
+ }
605
+ if (match.searchError) {
606
+ handleErrorAndRedirect(match.searchError, 'VALIDATE_SEARCH');
607
+ }
608
+ const parentContext = parentMatch?.context ?? this.options.context ?? {};
609
+ const beforeLoadContext = (await route.options.beforeLoad?.({
610
+ search: match.search,
611
+ abortController: match.abortController,
612
+ params: match.params,
613
+ preload: !!preload,
614
+ context: parentContext,
615
+ location: this.state.location,
616
+ // TOOD: just expose state and router, etc
617
+ navigate: opts => this.navigate({
618
+ ...opts,
619
+ from: match.pathname
620
+ }),
621
+ buildLocation: this.buildLocation,
622
+ cause: match.cause
623
+ })) ?? {};
624
+ if (redirects.isRedirect(beforeLoadContext)) {
625
+ throw beforeLoadContext;
626
+ }
627
+ const context = {
628
+ ...parentContext,
629
+ ...beforeLoadContext
630
+ };
631
+ matches[index] = match = {
632
+ ...match,
633
+ context: utils.replaceEqualDeep(match.context, context)
634
+ };
635
+ } catch (err) {
636
+ handleErrorAndRedirect(err, 'BEFORE_LOAD');
637
+ break;
638
+ }
639
+ }
640
+ } catch (err) {
641
+ if (redirects.isRedirect(err)) {
642
+ if (!preload) this.navigate(err);
643
+ return matches;
644
+ }
645
+ throw err;
646
+ }
647
+ const validResolvedMatches = matches.slice(0, firstBadMatchIndex);
648
+ const matchPromises = [];
649
+ validResolvedMatches.forEach((match, index) => {
650
+ matchPromises.push((async () => {
651
+ const parentMatchPromise = matchPromises[index - 1];
652
+ const route = this.looseRoutesById[match.routeId];
653
+ const handleErrorAndRedirect = err => {
654
+ if (redirects.isRedirect(err)) {
655
+ if (!preload) {
656
+ this.navigate(err);
657
+ }
658
+ return true;
659
+ }
660
+ return false;
661
+ };
662
+ let loadPromise;
663
+ matches[index] = match = {
664
+ ...match,
665
+ fetchedAt: Date.now(),
666
+ invalid: false,
667
+ showPending: false
668
+ };
669
+ const pendingMs = route.options.pendingMs ?? this.options.defaultPendingMs;
670
+ let pendingPromise;
671
+ if (!preload && pendingMs && (route.options.pendingComponent ?? this.options.defaultPendingComponent)) {
672
+ pendingPromise = new Promise(r => setTimeout(r, pendingMs));
673
+ }
674
+ if (match.isFetching) {
675
+ loadPromise = RouterProvider.getRouteMatch(this.state, match.id)?.loadPromise;
676
+ } else {
677
+ const loaderContext = {
678
+ params: match.params,
679
+ search: match.search,
680
+ preload: !!preload,
681
+ parentMatchPromise,
682
+ abortController: match.abortController,
683
+ context: match.context,
684
+ location: this.state.location,
685
+ navigate: opts => this.navigate({
686
+ ...opts,
687
+ from: match.pathname
688
+ }),
689
+ cause: match.cause
690
+ };
691
+
692
+ // Default to reloading the route all the time
693
+ let shouldReload = true;
694
+ let shouldReloadDeps = typeof route.options.shouldReload === 'function' ? route.options.shouldReload?.(loaderContext) : !!(route.options.shouldReload ?? true);
695
+ if (match.cause === 'enter' || invalidate) {
696
+ match.shouldReloadDeps = shouldReloadDeps;
697
+ } else if (match.cause === 'stay') {
698
+ if (typeof shouldReloadDeps === 'object') {
699
+ // compare the deps to see if they've changed
700
+ shouldReload = !utils.deepEqual(shouldReloadDeps, match.shouldReloadDeps);
701
+ match.shouldReloadDeps = shouldReloadDeps;
702
+ } else {
703
+ shouldReload = !!shouldReloadDeps;
704
+ }
705
+ }
706
+
707
+ // If the user doesn't want the route to reload, just
708
+ // resolve with the existing loader data
709
+
710
+ if (!shouldReload) {
711
+ loadPromise = Promise.resolve(match.loaderData);
712
+ } else {
713
+ // Otherwise, load the route
714
+ matches[index] = match = {
715
+ ...match,
716
+ isFetching: true
717
+ };
718
+ const componentsPromise = Promise.all(componentTypes.map(async type => {
719
+ const component = route.options[type];
720
+ if (component?.preload) {
721
+ await component.preload();
722
+ }
723
+ }));
724
+ const loaderPromise = route.options.loader?.(loaderContext);
725
+ loadPromise = Promise.all([componentsPromise, loaderPromise]).then(d => d[1]);
726
+ }
727
+ }
728
+ matches[index] = match = {
729
+ ...match,
730
+ loadPromise
731
+ };
732
+ if (!preload) {
733
+ updatePendingMatch(match);
734
+ }
735
+ let didShowPending = false;
736
+ const pendingMinMs = route.options.pendingMinMs ?? this.options.defaultPendingMinMs;
737
+ await new Promise(async resolve => {
738
+ // If the route has a pending component and a pendingMs option,
739
+ // forcefully show the pending component
740
+ if (pendingPromise) {
741
+ pendingPromise.then(() => {
742
+ if (latestPromise = checkLatest()) return;
743
+ didShowPending = true;
744
+ matches[index] = match = {
745
+ ...match,
746
+ showPending: true
747
+ };
748
+ updatePendingMatch(match);
749
+ resolve();
750
+ });
751
+ }
752
+ try {
753
+ const loaderData = await loadPromise;
754
+ if (latestPromise = checkLatest()) return await latestPromise;
755
+ if (redirects.isRedirect(loaderData)) {
756
+ if (handleErrorAndRedirect(loaderData)) return;
757
+ }
758
+ if (didShowPending && pendingMinMs) {
759
+ await new Promise(r => setTimeout(r, pendingMinMs));
760
+ }
761
+ if (latestPromise = checkLatest()) return await latestPromise;
762
+ matches[index] = match = {
763
+ ...match,
764
+ error: undefined,
765
+ status: 'success',
766
+ isFetching: false,
767
+ updatedAt: Date.now(),
768
+ loaderData,
769
+ loadPromise: undefined
770
+ };
771
+ } catch (error) {
772
+ if (latestPromise = checkLatest()) return await latestPromise;
773
+ if (handleErrorAndRedirect(error)) return;
774
+ try {
775
+ route.options.onError?.(error);
776
+ } catch (onErrorError) {
777
+ error = onErrorError;
778
+ if (handleErrorAndRedirect(onErrorError)) return;
779
+ }
780
+ matches[index] = match = {
781
+ ...match,
782
+ error,
783
+ status: 'error',
784
+ isFetching: false,
785
+ updatedAt: Date.now()
786
+ };
787
+ } finally {
788
+ // If we showed the pending component, that means
789
+ // we already moved the pendingMatches to the matches
790
+ // state, so we need to update that specific match
791
+ if (didShowPending && pendingMinMs && match.showPending) {
792
+ this.__store.setState(s => ({
793
+ ...s,
794
+ matches: s.matches?.map(d => d.id === match.id ? match : d)
795
+ }));
796
+ }
797
+ }
798
+ if (!preload) {
799
+ updatePendingMatch(match);
800
+ }
801
+ resolve();
802
+ });
803
+ })());
804
+ });
805
+ await Promise.all(matchPromises);
806
+ return matches;
807
+ };
808
+ invalidate = () => this.load({
809
+ invalidate: true
810
+ });
811
+ load = async opts => {
812
+ const promise = new Promise(async (resolve, reject) => {
813
+ const next = this.latestLocation;
814
+ const prevLocation = this.state.resolvedLocation;
815
+ const pathDidChange = prevLocation.href !== next.href;
816
+ let latestPromise;
817
+
818
+ // Cancel any pending matches
819
+ this.cancelMatches();
820
+ this.emit({
821
+ type: 'onBeforeLoad',
822
+ fromLocation: prevLocation,
823
+ toLocation: next,
824
+ pathChanged: pathDidChange
825
+ });
826
+
827
+ // Match the routes
828
+ let pendingMatches = this.matchRoutes(next.pathname, next.search, {
829
+ debug: true
830
+ });
831
+ const previousMatches = this.state.matches;
832
+
833
+ // Ingest the new matches
834
+ this.__store.setState(s => ({
835
+ ...s,
836
+ isLoading: true,
837
+ location: next,
838
+ pendingMatches
839
+ }));
840
+ try {
841
+ try {
842
+ // Load the matches
843
+ await this.loadMatches({
844
+ matches: pendingMatches,
845
+ checkLatest: () => this.checkLatest(promise),
846
+ invalidate: opts?.invalidate
847
+ });
848
+ } catch (err) {
849
+ // swallow this error, since we'll display the
850
+ // errors on the route components
851
+ }
852
+
853
+ // Only apply the latest transition
854
+ if (latestPromise = this.checkLatest(promise)) {
855
+ return latestPromise;
856
+ }
857
+ const exitingMatchIds = previousMatches.filter(id => !this.pendingMatches.includes(id));
858
+ const enteringMatchIds = this.pendingMatches.filter(id => !previousMatches.includes(id));
859
+ const stayingMatchIds = previousMatches.filter(id => this.pendingMatches.includes(id));
860
+ this.__store.setState(s => ({
861
+ ...s,
862
+ isLoading: false,
863
+ matches: pendingMatches,
864
+ pendingMatches: undefined
865
+ }))
866
+
867
+ //
868
+ ;
869
+ [[exitingMatchIds, 'onLeave'], [enteringMatchIds, 'onEnter'], [stayingMatchIds, 'onTransition']].forEach(([matches, hook]) => {
870
+ matches.forEach(match => {
871
+ this.looseRoutesById[match.routeId].options[hook]?.(match);
872
+ });
873
+ });
874
+ this.emit({
875
+ type: 'onLoad',
876
+ fromLocation: prevLocation,
877
+ toLocation: next,
878
+ pathChanged: pathDidChange
879
+ });
880
+ resolve();
881
+ } catch (err) {
882
+ // Only apply the latest transition
883
+ if (latestPromise = this.checkLatest(promise)) {
884
+ return latestPromise;
885
+ }
886
+ reject(err);
887
+ }
888
+ });
889
+ this.latestLoadPromise = promise;
890
+ return this.latestLoadPromise;
891
+ };
892
+ preloadRoute = async (navigateOpts = this.state.location) => {
893
+ let next = this.buildLocation(navigateOpts);
894
+ let matches = this.matchRoutes(next.pathname, next.search, {
895
+ throwOnError: true
896
+ });
897
+ matches = await this.loadMatches({
898
+ matches,
899
+ preload: true,
900
+ checkLatest: () => undefined
901
+ });
902
+ return matches;
903
+ };
904
+ buildLink = dest => {
905
+ // If this link simply reloads the current route,
906
+ // make sure it has a new key so it will trigger a data refresh
907
+
908
+ // If this `to` is a valid external URL, return
909
+ // null for LinkUtils
910
+
911
+ const {
912
+ to,
913
+ preload: userPreload,
914
+ preloadDelay: userPreloadDelay,
915
+ activeOptions,
916
+ disabled,
917
+ target,
918
+ replace,
919
+ resetScroll,
920
+ startTransition
921
+ } = dest;
922
+ try {
923
+ new URL(`${to}`);
924
+ return {
925
+ type: 'external',
926
+ href: to
927
+ };
928
+ } catch (e) {}
929
+ const nextOpts = dest;
930
+ const next = this.buildLocation(nextOpts);
931
+ const preload = userPreload ?? this.options.defaultPreload;
932
+ const preloadDelay = userPreloadDelay ?? this.options.defaultPreloadDelay ?? 0;
933
+
934
+ // Compare path/hash for matches
935
+ const currentPathSplit = this.latestLocation.pathname.split('/');
936
+ const nextPathSplit = next.pathname.split('/');
937
+ const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
938
+ // Combine the matches based on user this.options
939
+ const pathTest = activeOptions?.exact ? this.latestLocation.pathname === next.pathname : pathIsFuzzyEqual;
940
+ const hashTest = activeOptions?.includeHash ? this.latestLocation.hash === next.hash : true;
941
+ const searchTest = activeOptions?.includeSearch ?? true ? utils.deepEqual(this.latestLocation.search, next.search, true) : true;
942
+
943
+ // The final "active" test
944
+ const isActive = pathTest && hashTest && searchTest;
945
+
946
+ // The click handler
947
+ const handleClick = e => {
948
+ if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
949
+ e.preventDefault();
950
+
951
+ // All is well? Navigate!
952
+ this.commitLocation({
953
+ ...next,
954
+ replace,
955
+ resetScroll,
956
+ startTransition
957
+ });
958
+ }
959
+ };
960
+
961
+ // The click handler
962
+ const handleFocus = e => {
963
+ if (preload) {
964
+ this.preloadRoute(nextOpts).catch(err => {
965
+ console.warn(err);
966
+ console.warn(preloadWarning);
967
+ });
968
+ }
969
+ };
970
+ const handleTouchStart = e => {
971
+ if (preload) {
972
+ this.preloadRoute(nextOpts).catch(err => {
973
+ console.warn(err);
974
+ console.warn(preloadWarning);
975
+ });
976
+ }
977
+ };
978
+ const handleEnter = e => {
979
+ const target = e.target || {};
980
+ if (preload) {
981
+ if (target.preloadTimeout) {
982
+ return;
983
+ }
984
+ target.preloadTimeout = setTimeout(() => {
985
+ target.preloadTimeout = null;
986
+ this.preloadRoute(nextOpts).catch(err => {
987
+ console.warn(err);
988
+ console.warn(preloadWarning);
989
+ });
990
+ }, preloadDelay);
991
+ }
992
+ };
993
+ const handleLeave = e => {
994
+ const target = e.target || {};
995
+ if (target.preloadTimeout) {
996
+ clearTimeout(target.preloadTimeout);
997
+ target.preloadTimeout = null;
998
+ }
999
+ };
1000
+ return {
1001
+ type: 'internal',
1002
+ next,
1003
+ handleFocus,
1004
+ handleClick,
1005
+ handleEnter,
1006
+ handleLeave,
1007
+ handleTouchStart,
1008
+ isActive,
1009
+ disabled
1010
+ };
1011
+ };
1012
+ matchRoute = (location, opts) => {
1013
+ location = {
1014
+ ...location,
1015
+ to: location.to ? this.resolvePathWithBase(location.from || '', location.to) : undefined
1016
+ };
1017
+ const next = this.buildLocation(location);
1018
+ if (opts?.pending && this.state.status !== 'pending') {
1019
+ return false;
1020
+ }
1021
+ const baseLocation = opts?.pending ? this.latestLocation : this.state.resolvedLocation;
1022
+ if (!baseLocation) {
1023
+ return false;
1024
+ }
1025
+ const match = path.matchPathname(this.basepath, baseLocation.pathname, {
1026
+ ...opts,
1027
+ to: next.pathname
1028
+ });
1029
+ if (!match) {
1030
+ return false;
1031
+ }
1032
+ if (match && (opts?.includeSearch ?? true)) {
1033
+ return utils.deepEqual(baseLocation.search, next.search, true) ? match : false;
1034
+ }
1035
+ return match;
1036
+ };
1037
+ injectHtml = async html => {
1038
+ this.injectedHtml.push(html);
1039
+ };
1040
+ dehydrateData = (key, getData) => {
1041
+ if (typeof document === 'undefined') {
1042
+ const strKey = typeof key === 'string' ? key : JSON.stringify(key);
1043
+ this.injectHtml(async () => {
1044
+ const id = `__TSR_DEHYDRATED__${strKey}`;
1045
+ const data = typeof getData === 'function' ? await getData() : getData;
1046
+ return `<script id='${id}' suppressHydrationWarning>window["__TSR_DEHYDRATED__${utils.escapeJSON(strKey)}"] = ${JSON.stringify(data)}
1047
+ ;(() => {
1048
+ var el = document.getElementById('${id}')
1049
+ el.parentElement.removeChild(el)
1050
+ })()
1051
+ </script>`;
1052
+ });
1053
+ return () => this.hydrateData(key);
1054
+ }
1055
+ return () => undefined;
1056
+ };
1057
+ hydrateData = key => {
1058
+ if (typeof document !== 'undefined') {
1059
+ const strKey = typeof key === 'string' ? key : JSON.stringify(key);
1060
+ return window[`__TSR_DEHYDRATED__${strKey}`];
1061
+ }
1062
+ return undefined;
1063
+ };
1064
+ dehydrate = () => {
1065
+ return {
1066
+ state: {
1067
+ dehydratedMatches: this.state.matches.map(d => utils.pick(d, ['fetchedAt', 'invalid', 'id', 'status', 'updatedAt', 'loaderData']))
1068
+ }
1069
+ };
1070
+ };
1071
+ hydrate = async __do_not_use_server_ctx => {
1072
+ let _ctx = __do_not_use_server_ctx;
1073
+ // Client hydrates from window
1074
+ if (typeof document !== 'undefined') {
1075
+ _ctx = window.__TSR_DEHYDRATED__;
1076
+ }
1077
+ invariant(_ctx, 'Expected to find a __TSR_DEHYDRATED__ property on window... but we did not. Did you forget to render <DehydrateRouter /> in your app?');
1078
+ const ctx = _ctx;
1079
+ this.dehydratedData = ctx.payload;
1080
+ this.options.hydrate?.(ctx.payload);
1081
+ const dehydratedState = ctx.router.state;
1082
+ let matches = this.matchRoutes(this.state.location.pathname, this.state.location.search).map(match => {
1083
+ const dehydratedMatch = dehydratedState.dehydratedMatches.find(d => d.id === match.id);
1084
+ invariant(dehydratedMatch, `Could not find a client-side match for dehydrated match with id: ${match.id}!`);
1085
+ if (dehydratedMatch) {
1086
+ return {
1087
+ ...match,
1088
+ ...dehydratedMatch
1089
+ };
1090
+ }
1091
+ return match;
1092
+ });
1093
+ this.__store.setState(s => {
1094
+ return {
1095
+ ...s,
1096
+ matches: matches
1097
+ };
1098
+ });
1099
+ };
1100
+
1101
+ // resolveMatchPromise = (matchId: string, key: string, value: any) => {
1102
+ // state.matches
1103
+ // .find((d) => d.id === matchId)
1104
+ // ?.__promisesByKey[key]?.resolve(value)
1105
+ // }
1106
+ }
1107
+
1108
+ // A function that takes an import() argument which is a function and returns a new function that will
1109
+ // proxy arguments from the caller to the imported function, retaining all type
1110
+ // information along the way
1111
+ function lazyFn(fn, key) {
1112
+ return async (...args) => {
1113
+ const imported = await fn();
1114
+ return imported[key || 'default'](...args);
1115
+ };
1116
+ }
1117
+ function isCtrlEvent(e) {
1118
+ return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
1119
+ }
1120
+ class SearchParamError extends Error {}
1121
+ class PathParamError extends Error {}
1122
+ function getInitialRouterState(location) {
1123
+ return {
1124
+ isLoading: false,
1125
+ isTransitioning: false,
1126
+ status: 'idle',
1127
+ resolvedLocation: {
1128
+ ...location
1129
+ },
1130
+ location,
1131
+ matches: [],
1132
+ pendingMatches: [],
1133
+ lastUpdated: Date.now()
1134
+ };
1135
+ }
1136
+
1137
+ exports.PathParamError = PathParamError;
1138
+ exports.Router = Router;
1139
+ exports.SearchParamError = SearchParamError;
1140
+ exports.componentTypes = componentTypes;
1141
+ exports.getInitialRouterState = getInitialRouterState;
1142
+ exports.lazyFn = lazyFn;
1143
+ //# sourceMappingURL=router.js.map