@tanstack/react-router 0.0.1-beta.28 → 0.0.1-beta.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -5
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/cjs/{react-router/src/index.js → index.js} +63 -124
- package/build/cjs/index.js.map +1 -0
- package/build/esm/index.js +76 -2601
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +59 -49
- package/build/stats-react.json +115 -33
- package/build/types/index.d.ts +10 -19
- package/build/umd/index.development.js +204 -389
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +3 -3
- package/src/index.tsx +60 -50
- package/build/cjs/react-router/src/index.js.map +0 -1
- package/build/cjs/router-core/build/esm/index.js +0 -2530
- package/build/cjs/router-core/build/esm/index.js.map +0 -1
package/build/esm/index.js
CHANGED
|
@@ -10,2539 +10,50 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import * as React from 'react';
|
|
12
12
|
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
13
|
+
import { createRouter, rootRouteId, warning, invariant, functionalUpdate } from '@tanstack/router-core';
|
|
14
|
+
export * from '@tanstack/router-core';
|
|
13
15
|
|
|
14
|
-
function _extends
|
|
15
|
-
_extends
|
|
16
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
17
|
-
var source = arguments[i];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
target[key] = source[key];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return target;
|
|
27
|
-
};
|
|
28
|
-
return _extends$2.apply(this, arguments);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
32
|
-
if (source == null) return {};
|
|
33
|
-
var target = {};
|
|
34
|
-
var sourceKeys = Object.keys(source);
|
|
35
|
-
var key, i;
|
|
36
|
-
|
|
37
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
38
|
-
key = sourceKeys[i];
|
|
39
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
40
|
-
target[key] = source[key];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return target;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* router-core
|
|
48
|
-
*
|
|
49
|
-
* Copyright (c) TanStack
|
|
50
|
-
*
|
|
51
|
-
* This source code is licensed under the MIT license found in the
|
|
52
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
53
|
-
*
|
|
54
|
-
* @license MIT
|
|
55
|
-
*/
|
|
56
|
-
function _extends$1() {
|
|
57
|
-
_extends$1 = Object.assign ? Object.assign.bind() : function (target) {
|
|
58
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
59
|
-
var source = arguments[i];
|
|
60
|
-
|
|
61
|
-
for (var key in source) {
|
|
62
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
63
|
-
target[key] = source[key];
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return target;
|
|
69
|
-
};
|
|
70
|
-
return _extends$1.apply(this, arguments);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Actions represent the type of change to a location value.
|
|
75
|
-
*
|
|
76
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#action
|
|
77
|
-
*/
|
|
78
|
-
var Action;
|
|
79
|
-
|
|
80
|
-
(function (Action) {
|
|
81
|
-
/**
|
|
82
|
-
* A POP indicates a change to an arbitrary index in the history stack, such
|
|
83
|
-
* as a back or forward navigation. It does not describe the direction of the
|
|
84
|
-
* navigation, only that the current index changed.
|
|
85
|
-
*
|
|
86
|
-
* Note: This is the default action for newly created history objects.
|
|
87
|
-
*/
|
|
88
|
-
Action["Pop"] = "POP";
|
|
89
|
-
/**
|
|
90
|
-
* A PUSH indicates a new entry being added to the history stack, such as when
|
|
91
|
-
* a link is clicked and a new page loads. When this happens, all subsequent
|
|
92
|
-
* entries in the stack are lost.
|
|
93
|
-
*/
|
|
94
|
-
|
|
95
|
-
Action["Push"] = "PUSH";
|
|
96
|
-
/**
|
|
97
|
-
* A REPLACE indicates the entry at the current index in the history stack
|
|
98
|
-
* being replaced by a new one.
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
|
-
Action["Replace"] = "REPLACE";
|
|
102
|
-
})(Action || (Action = {}));
|
|
103
|
-
|
|
104
|
-
var readOnly = process.env.NODE_ENV !== "production" ? function (obj) {
|
|
105
|
-
return Object.freeze(obj);
|
|
106
|
-
} : function (obj) {
|
|
107
|
-
return obj;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
function warning$1(cond, message) {
|
|
111
|
-
if (!cond) {
|
|
112
|
-
// eslint-disable-next-line no-console
|
|
113
|
-
if (typeof console !== 'undefined') console.warn(message);
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
// Welcome to debugging history!
|
|
117
|
-
//
|
|
118
|
-
// This error is thrown as a convenience so you can more easily
|
|
119
|
-
// find the source for a warning that appears in the console by
|
|
120
|
-
// enabling "pause on exceptions" in your JavaScript debugger.
|
|
121
|
-
throw new Error(message); // eslint-disable-next-line no-empty
|
|
122
|
-
} catch (e) {}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
var BeforeUnloadEventType = 'beforeunload';
|
|
127
|
-
var HashChangeEventType = 'hashchange';
|
|
128
|
-
var PopStateEventType = 'popstate';
|
|
129
|
-
/**
|
|
130
|
-
* Browser history stores the location in regular URLs. This is the standard for
|
|
131
|
-
* most web apps, but it requires some configuration on the server to ensure you
|
|
132
|
-
* serve the same app at multiple URLs.
|
|
133
|
-
*
|
|
134
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
|
|
135
|
-
*/
|
|
136
|
-
|
|
137
|
-
function createBrowserHistory(options) {
|
|
138
|
-
if (options === void 0) {
|
|
139
|
-
options = {};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
var _options = options,
|
|
143
|
-
_options$window = _options.window,
|
|
144
|
-
window = _options$window === void 0 ? document.defaultView : _options$window;
|
|
145
|
-
var globalHistory = window.history;
|
|
146
|
-
|
|
147
|
-
function getIndexAndLocation() {
|
|
148
|
-
var _window$location = window.location,
|
|
149
|
-
pathname = _window$location.pathname,
|
|
150
|
-
search = _window$location.search,
|
|
151
|
-
hash = _window$location.hash;
|
|
152
|
-
var state = globalHistory.state || {};
|
|
153
|
-
return [state.idx, readOnly({
|
|
154
|
-
pathname: pathname,
|
|
155
|
-
search: search,
|
|
156
|
-
hash: hash,
|
|
157
|
-
state: state.usr || null,
|
|
158
|
-
key: state.key || 'default'
|
|
159
|
-
})];
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
var blockedPopTx = null;
|
|
163
|
-
|
|
164
|
-
function handlePop() {
|
|
165
|
-
if (blockedPopTx) {
|
|
166
|
-
blockers.call(blockedPopTx);
|
|
167
|
-
blockedPopTx = null;
|
|
168
|
-
} else {
|
|
169
|
-
var nextAction = Action.Pop;
|
|
170
|
-
|
|
171
|
-
var _getIndexAndLocation = getIndexAndLocation(),
|
|
172
|
-
nextIndex = _getIndexAndLocation[0],
|
|
173
|
-
nextLocation = _getIndexAndLocation[1];
|
|
174
|
-
|
|
175
|
-
if (blockers.length) {
|
|
176
|
-
if (nextIndex != null) {
|
|
177
|
-
var delta = index - nextIndex;
|
|
178
|
-
|
|
179
|
-
if (delta) {
|
|
180
|
-
// Revert the POP
|
|
181
|
-
blockedPopTx = {
|
|
182
|
-
action: nextAction,
|
|
183
|
-
location: nextLocation,
|
|
184
|
-
retry: function retry() {
|
|
185
|
-
go(delta * -1);
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
go(delta);
|
|
189
|
-
}
|
|
190
|
-
} else {
|
|
191
|
-
// Trying to POP to a location with no index. We did not create
|
|
192
|
-
// this location, so we can't effectively block the navigation.
|
|
193
|
-
process.env.NODE_ENV !== "production" ? warning$1(false, // TODO: Write up a doc that explains our blocking strategy in
|
|
194
|
-
// detail and link to it here so people can understand better what
|
|
195
|
-
// is going on and how to avoid it.
|
|
196
|
-
"You are trying to block a POP navigation to a location that was not " + "created by the history library. The block will fail silently in " + "production, but in general you should do all navigation with the " + "history library (instead of using window.history.pushState directly) " + "to avoid this situation.") : void 0;
|
|
197
|
-
}
|
|
198
|
-
} else {
|
|
199
|
-
applyTx(nextAction);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
window.addEventListener(PopStateEventType, handlePop);
|
|
205
|
-
var action = Action.Pop;
|
|
206
|
-
|
|
207
|
-
var _getIndexAndLocation2 = getIndexAndLocation(),
|
|
208
|
-
index = _getIndexAndLocation2[0],
|
|
209
|
-
location = _getIndexAndLocation2[1];
|
|
210
|
-
|
|
211
|
-
var listeners = createEvents();
|
|
212
|
-
var blockers = createEvents();
|
|
213
|
-
|
|
214
|
-
if (index == null) {
|
|
215
|
-
index = 0;
|
|
216
|
-
globalHistory.replaceState(_extends$1({}, globalHistory.state, {
|
|
217
|
-
idx: index
|
|
218
|
-
}), '');
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function createHref(to) {
|
|
222
|
-
return typeof to === 'string' ? to : createPath(to);
|
|
223
|
-
} // state defaults to `null` because `window.history.state` does
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
function getNextLocation(to, state) {
|
|
227
|
-
if (state === void 0) {
|
|
228
|
-
state = null;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return readOnly(_extends$1({
|
|
232
|
-
pathname: location.pathname,
|
|
233
|
-
hash: '',
|
|
234
|
-
search: ''
|
|
235
|
-
}, typeof to === 'string' ? parsePath(to) : to, {
|
|
236
|
-
state: state,
|
|
237
|
-
key: createKey()
|
|
238
|
-
}));
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function getHistoryStateAndUrl(nextLocation, index) {
|
|
242
|
-
return [{
|
|
243
|
-
usr: nextLocation.state,
|
|
244
|
-
key: nextLocation.key,
|
|
245
|
-
idx: index
|
|
246
|
-
}, createHref(nextLocation)];
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
function allowTx(action, location, retry) {
|
|
250
|
-
return !blockers.length || (blockers.call({
|
|
251
|
-
action: action,
|
|
252
|
-
location: location,
|
|
253
|
-
retry: retry
|
|
254
|
-
}), false);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function applyTx(nextAction) {
|
|
258
|
-
action = nextAction;
|
|
259
|
-
|
|
260
|
-
var _getIndexAndLocation3 = getIndexAndLocation();
|
|
261
|
-
|
|
262
|
-
index = _getIndexAndLocation3[0];
|
|
263
|
-
location = _getIndexAndLocation3[1];
|
|
264
|
-
listeners.call({
|
|
265
|
-
action: action,
|
|
266
|
-
location: location
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function push(to, state) {
|
|
271
|
-
var nextAction = Action.Push;
|
|
272
|
-
var nextLocation = getNextLocation(to, state);
|
|
273
|
-
|
|
274
|
-
function retry() {
|
|
275
|
-
push(to, state);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
279
|
-
var _getHistoryStateAndUr = getHistoryStateAndUrl(nextLocation, index + 1),
|
|
280
|
-
historyState = _getHistoryStateAndUr[0],
|
|
281
|
-
url = _getHistoryStateAndUr[1]; // TODO: Support forced reloading
|
|
282
|
-
// try...catch because iOS limits us to 100 pushState calls :/
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
try {
|
|
286
|
-
globalHistory.pushState(historyState, '', url);
|
|
287
|
-
} catch (error) {
|
|
288
|
-
// They are going to lose state here, but there is no real
|
|
289
|
-
// way to warn them about it since the page will refresh...
|
|
290
|
-
window.location.assign(url);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
applyTx(nextAction);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
function replace(to, state) {
|
|
298
|
-
var nextAction = Action.Replace;
|
|
299
|
-
var nextLocation = getNextLocation(to, state);
|
|
300
|
-
|
|
301
|
-
function retry() {
|
|
302
|
-
replace(to, state);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
306
|
-
var _getHistoryStateAndUr2 = getHistoryStateAndUrl(nextLocation, index),
|
|
307
|
-
historyState = _getHistoryStateAndUr2[0],
|
|
308
|
-
url = _getHistoryStateAndUr2[1]; // TODO: Support forced reloading
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
globalHistory.replaceState(historyState, '', url);
|
|
312
|
-
applyTx(nextAction);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
function go(delta) {
|
|
317
|
-
globalHistory.go(delta);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
var history = {
|
|
321
|
-
get action() {
|
|
322
|
-
return action;
|
|
323
|
-
},
|
|
324
|
-
|
|
325
|
-
get location() {
|
|
326
|
-
return location;
|
|
327
|
-
},
|
|
328
|
-
|
|
329
|
-
createHref: createHref,
|
|
330
|
-
push: push,
|
|
331
|
-
replace: replace,
|
|
332
|
-
go: go,
|
|
333
|
-
back: function back() {
|
|
334
|
-
go(-1);
|
|
335
|
-
},
|
|
336
|
-
forward: function forward() {
|
|
337
|
-
go(1);
|
|
338
|
-
},
|
|
339
|
-
listen: function listen(listener) {
|
|
340
|
-
return listeners.push(listener);
|
|
341
|
-
},
|
|
342
|
-
block: function block(blocker) {
|
|
343
|
-
var unblock = blockers.push(blocker);
|
|
344
|
-
|
|
345
|
-
if (blockers.length === 1) {
|
|
346
|
-
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
return function () {
|
|
350
|
-
unblock(); // Remove the beforeunload listener so the document may
|
|
351
|
-
// still be salvageable in the pagehide event.
|
|
352
|
-
// See https://html.spec.whatwg.org/#unloading-documents
|
|
353
|
-
|
|
354
|
-
if (!blockers.length) {
|
|
355
|
-
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
return history;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Hash history stores the location in window.location.hash. This makes it ideal
|
|
364
|
-
* for situations where you don't want to send the location to the server for
|
|
365
|
-
* some reason, either because you do cannot configure it or the URL space is
|
|
366
|
-
* reserved for something else.
|
|
367
|
-
*
|
|
368
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
|
|
369
|
-
*/
|
|
370
|
-
|
|
371
|
-
function createHashHistory(options) {
|
|
372
|
-
if (options === void 0) {
|
|
373
|
-
options = {};
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
var _options2 = options,
|
|
377
|
-
_options2$window = _options2.window,
|
|
378
|
-
window = _options2$window === void 0 ? document.defaultView : _options2$window;
|
|
379
|
-
var globalHistory = window.history;
|
|
380
|
-
|
|
381
|
-
function getIndexAndLocation() {
|
|
382
|
-
var _parsePath = parsePath(window.location.hash.substr(1)),
|
|
383
|
-
_parsePath$pathname = _parsePath.pathname,
|
|
384
|
-
pathname = _parsePath$pathname === void 0 ? '/' : _parsePath$pathname,
|
|
385
|
-
_parsePath$search = _parsePath.search,
|
|
386
|
-
search = _parsePath$search === void 0 ? '' : _parsePath$search,
|
|
387
|
-
_parsePath$hash = _parsePath.hash,
|
|
388
|
-
hash = _parsePath$hash === void 0 ? '' : _parsePath$hash;
|
|
389
|
-
|
|
390
|
-
var state = globalHistory.state || {};
|
|
391
|
-
return [state.idx, readOnly({
|
|
392
|
-
pathname: pathname,
|
|
393
|
-
search: search,
|
|
394
|
-
hash: hash,
|
|
395
|
-
state: state.usr || null,
|
|
396
|
-
key: state.key || 'default'
|
|
397
|
-
})];
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
var blockedPopTx = null;
|
|
401
|
-
|
|
402
|
-
function handlePop() {
|
|
403
|
-
if (blockedPopTx) {
|
|
404
|
-
blockers.call(blockedPopTx);
|
|
405
|
-
blockedPopTx = null;
|
|
406
|
-
} else {
|
|
407
|
-
var nextAction = Action.Pop;
|
|
408
|
-
|
|
409
|
-
var _getIndexAndLocation4 = getIndexAndLocation(),
|
|
410
|
-
nextIndex = _getIndexAndLocation4[0],
|
|
411
|
-
nextLocation = _getIndexAndLocation4[1];
|
|
412
|
-
|
|
413
|
-
if (blockers.length) {
|
|
414
|
-
if (nextIndex != null) {
|
|
415
|
-
var delta = index - nextIndex;
|
|
416
|
-
|
|
417
|
-
if (delta) {
|
|
418
|
-
// Revert the POP
|
|
419
|
-
blockedPopTx = {
|
|
420
|
-
action: nextAction,
|
|
421
|
-
location: nextLocation,
|
|
422
|
-
retry: function retry() {
|
|
423
|
-
go(delta * -1);
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
go(delta);
|
|
427
|
-
}
|
|
428
|
-
} else {
|
|
429
|
-
// Trying to POP to a location with no index. We did not create
|
|
430
|
-
// this location, so we can't effectively block the navigation.
|
|
431
|
-
process.env.NODE_ENV !== "production" ? warning$1(false, // TODO: Write up a doc that explains our blocking strategy in
|
|
432
|
-
// detail and link to it here so people can understand better
|
|
433
|
-
// what is going on and how to avoid it.
|
|
434
|
-
"You are trying to block a POP navigation to a location that was not " + "created by the history library. The block will fail silently in " + "production, but in general you should do all navigation with the " + "history library (instead of using window.history.pushState directly) " + "to avoid this situation.") : void 0;
|
|
435
|
-
}
|
|
436
|
-
} else {
|
|
437
|
-
applyTx(nextAction);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
window.addEventListener(PopStateEventType, handlePop); // popstate does not fire on hashchange in IE 11 and old (trident) Edge
|
|
443
|
-
// https://developer.mozilla.org/de/docs/Web/API/Window/popstate_event
|
|
444
|
-
|
|
445
|
-
window.addEventListener(HashChangeEventType, function () {
|
|
446
|
-
var _getIndexAndLocation5 = getIndexAndLocation(),
|
|
447
|
-
nextLocation = _getIndexAndLocation5[1]; // Ignore extraneous hashchange events.
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
if (createPath(nextLocation) !== createPath(location)) {
|
|
451
|
-
handlePop();
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
var action = Action.Pop;
|
|
455
|
-
|
|
456
|
-
var _getIndexAndLocation6 = getIndexAndLocation(),
|
|
457
|
-
index = _getIndexAndLocation6[0],
|
|
458
|
-
location = _getIndexAndLocation6[1];
|
|
459
|
-
|
|
460
|
-
var listeners = createEvents();
|
|
461
|
-
var blockers = createEvents();
|
|
462
|
-
|
|
463
|
-
if (index == null) {
|
|
464
|
-
index = 0;
|
|
465
|
-
globalHistory.replaceState(_extends$1({}, globalHistory.state, {
|
|
466
|
-
idx: index
|
|
467
|
-
}), '');
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
function getBaseHref() {
|
|
471
|
-
var base = document.querySelector('base');
|
|
472
|
-
var href = '';
|
|
473
|
-
|
|
474
|
-
if (base && base.getAttribute('href')) {
|
|
475
|
-
var url = window.location.href;
|
|
476
|
-
var hashIndex = url.indexOf('#');
|
|
477
|
-
href = hashIndex === -1 ? url : url.slice(0, hashIndex);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
return href;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
function createHref(to) {
|
|
484
|
-
return getBaseHref() + '#' + (typeof to === 'string' ? to : createPath(to));
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
function getNextLocation(to, state) {
|
|
488
|
-
if (state === void 0) {
|
|
489
|
-
state = null;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
return readOnly(_extends$1({
|
|
493
|
-
pathname: location.pathname,
|
|
494
|
-
hash: '',
|
|
495
|
-
search: ''
|
|
496
|
-
}, typeof to === 'string' ? parsePath(to) : to, {
|
|
497
|
-
state: state,
|
|
498
|
-
key: createKey()
|
|
499
|
-
}));
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
function getHistoryStateAndUrl(nextLocation, index) {
|
|
503
|
-
return [{
|
|
504
|
-
usr: nextLocation.state,
|
|
505
|
-
key: nextLocation.key,
|
|
506
|
-
idx: index
|
|
507
|
-
}, createHref(nextLocation)];
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
function allowTx(action, location, retry) {
|
|
511
|
-
return !blockers.length || (blockers.call({
|
|
512
|
-
action: action,
|
|
513
|
-
location: location,
|
|
514
|
-
retry: retry
|
|
515
|
-
}), false);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
function applyTx(nextAction) {
|
|
519
|
-
action = nextAction;
|
|
520
|
-
|
|
521
|
-
var _getIndexAndLocation7 = getIndexAndLocation();
|
|
522
|
-
|
|
523
|
-
index = _getIndexAndLocation7[0];
|
|
524
|
-
location = _getIndexAndLocation7[1];
|
|
525
|
-
listeners.call({
|
|
526
|
-
action: action,
|
|
527
|
-
location: location
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
function push(to, state) {
|
|
532
|
-
var nextAction = Action.Push;
|
|
533
|
-
var nextLocation = getNextLocation(to, state);
|
|
534
|
-
|
|
535
|
-
function retry() {
|
|
536
|
-
push(to, state);
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
process.env.NODE_ENV !== "production" ? warning$1(nextLocation.pathname.charAt(0) === '/', "Relative pathnames are not supported in hash history.push(" + JSON.stringify(to) + ")") : void 0;
|
|
540
|
-
|
|
541
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
542
|
-
var _getHistoryStateAndUr3 = getHistoryStateAndUrl(nextLocation, index + 1),
|
|
543
|
-
historyState = _getHistoryStateAndUr3[0],
|
|
544
|
-
url = _getHistoryStateAndUr3[1]; // TODO: Support forced reloading
|
|
545
|
-
// try...catch because iOS limits us to 100 pushState calls :/
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
try {
|
|
549
|
-
globalHistory.pushState(historyState, '', url);
|
|
550
|
-
} catch (error) {
|
|
551
|
-
// They are going to lose state here, but there is no real
|
|
552
|
-
// way to warn them about it since the page will refresh...
|
|
553
|
-
window.location.assign(url);
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
applyTx(nextAction);
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
function replace(to, state) {
|
|
561
|
-
var nextAction = Action.Replace;
|
|
562
|
-
var nextLocation = getNextLocation(to, state);
|
|
563
|
-
|
|
564
|
-
function retry() {
|
|
565
|
-
replace(to, state);
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
process.env.NODE_ENV !== "production" ? warning$1(nextLocation.pathname.charAt(0) === '/', "Relative pathnames are not supported in hash history.replace(" + JSON.stringify(to) + ")") : void 0;
|
|
569
|
-
|
|
570
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
571
|
-
var _getHistoryStateAndUr4 = getHistoryStateAndUrl(nextLocation, index),
|
|
572
|
-
historyState = _getHistoryStateAndUr4[0],
|
|
573
|
-
url = _getHistoryStateAndUr4[1]; // TODO: Support forced reloading
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
globalHistory.replaceState(historyState, '', url);
|
|
577
|
-
applyTx(nextAction);
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
function go(delta) {
|
|
582
|
-
globalHistory.go(delta);
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
var history = {
|
|
586
|
-
get action() {
|
|
587
|
-
return action;
|
|
588
|
-
},
|
|
589
|
-
|
|
590
|
-
get location() {
|
|
591
|
-
return location;
|
|
592
|
-
},
|
|
593
|
-
|
|
594
|
-
createHref: createHref,
|
|
595
|
-
push: push,
|
|
596
|
-
replace: replace,
|
|
597
|
-
go: go,
|
|
598
|
-
back: function back() {
|
|
599
|
-
go(-1);
|
|
600
|
-
},
|
|
601
|
-
forward: function forward() {
|
|
602
|
-
go(1);
|
|
603
|
-
},
|
|
604
|
-
listen: function listen(listener) {
|
|
605
|
-
return listeners.push(listener);
|
|
606
|
-
},
|
|
607
|
-
block: function block(blocker) {
|
|
608
|
-
var unblock = blockers.push(blocker);
|
|
609
|
-
|
|
610
|
-
if (blockers.length === 1) {
|
|
611
|
-
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
return function () {
|
|
615
|
-
unblock(); // Remove the beforeunload listener so the document may
|
|
616
|
-
// still be salvageable in the pagehide event.
|
|
617
|
-
// See https://html.spec.whatwg.org/#unloading-documents
|
|
618
|
-
|
|
619
|
-
if (!blockers.length) {
|
|
620
|
-
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
621
|
-
}
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
};
|
|
625
|
-
return history;
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* Memory history stores the current location in memory. It is designed for use
|
|
629
|
-
* in stateful non-browser environments like tests and React Native.
|
|
630
|
-
*
|
|
631
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#creatememoryhistory
|
|
632
|
-
*/
|
|
633
|
-
|
|
634
|
-
function createMemoryHistory(options) {
|
|
635
|
-
if (options === void 0) {
|
|
636
|
-
options = {};
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
var _options3 = options,
|
|
640
|
-
_options3$initialEntr = _options3.initialEntries,
|
|
641
|
-
initialEntries = _options3$initialEntr === void 0 ? ['/'] : _options3$initialEntr,
|
|
642
|
-
initialIndex = _options3.initialIndex;
|
|
643
|
-
var entries = initialEntries.map(function (entry) {
|
|
644
|
-
var location = readOnly(_extends$1({
|
|
645
|
-
pathname: '/',
|
|
646
|
-
search: '',
|
|
647
|
-
hash: '',
|
|
648
|
-
state: null,
|
|
649
|
-
key: createKey()
|
|
650
|
-
}, typeof entry === 'string' ? parsePath(entry) : entry));
|
|
651
|
-
process.env.NODE_ENV !== "production" ? warning$1(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: " + JSON.stringify(entry) + ")") : void 0;
|
|
652
|
-
return location;
|
|
653
|
-
});
|
|
654
|
-
var index = clamp(initialIndex == null ? entries.length - 1 : initialIndex, 0, entries.length - 1);
|
|
655
|
-
var action = Action.Pop;
|
|
656
|
-
var location = entries[index];
|
|
657
|
-
var listeners = createEvents();
|
|
658
|
-
var blockers = createEvents();
|
|
659
|
-
|
|
660
|
-
function createHref(to) {
|
|
661
|
-
return typeof to === 'string' ? to : createPath(to);
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
function getNextLocation(to, state) {
|
|
665
|
-
if (state === void 0) {
|
|
666
|
-
state = null;
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
return readOnly(_extends$1({
|
|
670
|
-
pathname: location.pathname,
|
|
671
|
-
search: '',
|
|
672
|
-
hash: ''
|
|
673
|
-
}, typeof to === 'string' ? parsePath(to) : to, {
|
|
674
|
-
state: state,
|
|
675
|
-
key: createKey()
|
|
676
|
-
}));
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
function allowTx(action, location, retry) {
|
|
680
|
-
return !blockers.length || (blockers.call({
|
|
681
|
-
action: action,
|
|
682
|
-
location: location,
|
|
683
|
-
retry: retry
|
|
684
|
-
}), false);
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
function applyTx(nextAction, nextLocation) {
|
|
688
|
-
action = nextAction;
|
|
689
|
-
location = nextLocation;
|
|
690
|
-
listeners.call({
|
|
691
|
-
action: action,
|
|
692
|
-
location: location
|
|
693
|
-
});
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
function push(to, state) {
|
|
697
|
-
var nextAction = Action.Push;
|
|
698
|
-
var nextLocation = getNextLocation(to, state);
|
|
699
|
-
|
|
700
|
-
function retry() {
|
|
701
|
-
push(to, state);
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
process.env.NODE_ENV !== "production" ? warning$1(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in memory history.push(" + JSON.stringify(to) + ")") : void 0;
|
|
705
|
-
|
|
706
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
707
|
-
index += 1;
|
|
708
|
-
entries.splice(index, entries.length, nextLocation);
|
|
709
|
-
applyTx(nextAction, nextLocation);
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
function replace(to, state) {
|
|
714
|
-
var nextAction = Action.Replace;
|
|
715
|
-
var nextLocation = getNextLocation(to, state);
|
|
716
|
-
|
|
717
|
-
function retry() {
|
|
718
|
-
replace(to, state);
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
process.env.NODE_ENV !== "production" ? warning$1(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in memory history.replace(" + JSON.stringify(to) + ")") : void 0;
|
|
722
|
-
|
|
723
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
724
|
-
entries[index] = nextLocation;
|
|
725
|
-
applyTx(nextAction, nextLocation);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
function go(delta) {
|
|
730
|
-
var nextIndex = clamp(index + delta, 0, entries.length - 1);
|
|
731
|
-
var nextAction = Action.Pop;
|
|
732
|
-
var nextLocation = entries[nextIndex];
|
|
733
|
-
|
|
734
|
-
function retry() {
|
|
735
|
-
go(delta);
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
739
|
-
index = nextIndex;
|
|
740
|
-
applyTx(nextAction, nextLocation);
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
var history = {
|
|
745
|
-
get index() {
|
|
746
|
-
return index;
|
|
747
|
-
},
|
|
748
|
-
|
|
749
|
-
get action() {
|
|
750
|
-
return action;
|
|
751
|
-
},
|
|
752
|
-
|
|
753
|
-
get location() {
|
|
754
|
-
return location;
|
|
755
|
-
},
|
|
756
|
-
|
|
757
|
-
createHref: createHref,
|
|
758
|
-
push: push,
|
|
759
|
-
replace: replace,
|
|
760
|
-
go: go,
|
|
761
|
-
back: function back() {
|
|
762
|
-
go(-1);
|
|
763
|
-
},
|
|
764
|
-
forward: function forward() {
|
|
765
|
-
go(1);
|
|
766
|
-
},
|
|
767
|
-
listen: function listen(listener) {
|
|
768
|
-
return listeners.push(listener);
|
|
769
|
-
},
|
|
770
|
-
block: function block(blocker) {
|
|
771
|
-
return blockers.push(blocker);
|
|
772
|
-
}
|
|
773
|
-
};
|
|
774
|
-
return history;
|
|
775
|
-
} ////////////////////////////////////////////////////////////////////////////////
|
|
776
|
-
// UTILS
|
|
777
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
778
|
-
|
|
779
|
-
function clamp(n, lowerBound, upperBound) {
|
|
780
|
-
return Math.min(Math.max(n, lowerBound), upperBound);
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
function promptBeforeUnload(event) {
|
|
784
|
-
// Cancel the event.
|
|
785
|
-
event.preventDefault(); // Chrome (and legacy IE) requires returnValue to be set.
|
|
786
|
-
|
|
787
|
-
event.returnValue = '';
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
function createEvents() {
|
|
791
|
-
var handlers = [];
|
|
792
|
-
return {
|
|
793
|
-
get length() {
|
|
794
|
-
return handlers.length;
|
|
795
|
-
},
|
|
796
|
-
|
|
797
|
-
push: function push(fn) {
|
|
798
|
-
handlers.push(fn);
|
|
799
|
-
return function () {
|
|
800
|
-
handlers = handlers.filter(function (handler) {
|
|
801
|
-
return handler !== fn;
|
|
802
|
-
});
|
|
803
|
-
};
|
|
804
|
-
},
|
|
805
|
-
call: function call(arg) {
|
|
806
|
-
handlers.forEach(function (fn) {
|
|
807
|
-
return fn && fn(arg);
|
|
808
|
-
});
|
|
809
|
-
}
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
function createKey() {
|
|
814
|
-
return Math.random().toString(36).substr(2, 8);
|
|
815
|
-
}
|
|
816
|
-
/**
|
|
817
|
-
* Creates a string URL path from the given pathname, search, and hash components.
|
|
818
|
-
*
|
|
819
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createpath
|
|
820
|
-
*/
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
function createPath(_ref) {
|
|
824
|
-
var _ref$pathname = _ref.pathname,
|
|
825
|
-
pathname = _ref$pathname === void 0 ? '/' : _ref$pathname,
|
|
826
|
-
_ref$search = _ref.search,
|
|
827
|
-
search = _ref$search === void 0 ? '' : _ref$search,
|
|
828
|
-
_ref$hash = _ref.hash,
|
|
829
|
-
hash = _ref$hash === void 0 ? '' : _ref$hash;
|
|
830
|
-
if (search && search !== '?') pathname += search.charAt(0) === '?' ? search : '?' + search;
|
|
831
|
-
if (hash && hash !== '#') pathname += hash.charAt(0) === '#' ? hash : '#' + hash;
|
|
832
|
-
return pathname;
|
|
833
|
-
}
|
|
834
|
-
/**
|
|
835
|
-
* Parses a string URL path into its separate pathname, search, and hash components.
|
|
836
|
-
*
|
|
837
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#parsepath
|
|
838
|
-
*/
|
|
839
|
-
|
|
840
|
-
function parsePath(path) {
|
|
841
|
-
var parsedPath = {};
|
|
842
|
-
|
|
843
|
-
if (path) {
|
|
844
|
-
var hashIndex = path.indexOf('#');
|
|
845
|
-
|
|
846
|
-
if (hashIndex >= 0) {
|
|
847
|
-
parsedPath.hash = path.substr(hashIndex);
|
|
848
|
-
path = path.substr(0, hashIndex);
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
var searchIndex = path.indexOf('?');
|
|
852
|
-
|
|
853
|
-
if (searchIndex >= 0) {
|
|
854
|
-
parsedPath.search = path.substr(searchIndex);
|
|
855
|
-
path = path.substr(0, searchIndex);
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
if (path) {
|
|
859
|
-
parsedPath.pathname = path;
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
return parsedPath;
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
var isProduction = process.env.NODE_ENV === 'production';
|
|
867
|
-
var prefix = 'Invariant failed';
|
|
868
|
-
function invariant(condition, message) {
|
|
869
|
-
if (condition) {
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
|
-
if (isProduction) {
|
|
873
|
-
throw new Error(prefix);
|
|
874
|
-
}
|
|
875
|
-
var provided = typeof message === 'function' ? message() : message;
|
|
876
|
-
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
|
877
|
-
throw new Error(value);
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
/**
|
|
881
|
-
* This function returns `a` if `b` is deeply equal.
|
|
882
|
-
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
883
|
-
* This can be used for structural sharing between JSON values for example.
|
|
884
|
-
*/
|
|
885
|
-
function replaceEqualDeep(prev, next) {
|
|
886
|
-
if (prev === next) {
|
|
887
|
-
return prev;
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
const array = Array.isArray(prev) && Array.isArray(next);
|
|
891
|
-
|
|
892
|
-
if (array || isPlainObject(prev) && isPlainObject(next)) {
|
|
893
|
-
const aSize = array ? prev.length : Object.keys(prev).length;
|
|
894
|
-
const bItems = array ? next : Object.keys(next);
|
|
895
|
-
const bSize = bItems.length;
|
|
896
|
-
const copy = array ? [] : {};
|
|
897
|
-
let equalItems = 0;
|
|
898
|
-
|
|
899
|
-
for (let i = 0; i < bSize; i++) {
|
|
900
|
-
const key = array ? i : bItems[i];
|
|
901
|
-
copy[key] = replaceEqualDeep(prev[key], next[key]);
|
|
902
|
-
|
|
903
|
-
if (copy[key] === prev[key]) {
|
|
904
|
-
equalItems++;
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
return aSize === bSize && equalItems === aSize ? prev : copy;
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
return next;
|
|
912
|
-
} // Copied from: https://github.com/jonschlinkert/is-plain-object
|
|
913
|
-
|
|
914
|
-
function isPlainObject(o) {
|
|
915
|
-
if (!hasObjectPrototype(o)) {
|
|
916
|
-
return false;
|
|
917
|
-
} // If has modified constructor
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
const ctor = o.constructor;
|
|
921
|
-
|
|
922
|
-
if (typeof ctor === 'undefined') {
|
|
923
|
-
return true;
|
|
924
|
-
} // If has modified prototype
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
const prot = ctor.prototype;
|
|
928
|
-
|
|
929
|
-
if (!hasObjectPrototype(prot)) {
|
|
930
|
-
return false;
|
|
931
|
-
} // If constructor does not have an Object-specific method
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
if (!prot.hasOwnProperty('isPrototypeOf')) {
|
|
935
|
-
return false;
|
|
936
|
-
} // Most likely a plain Object
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
return true;
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
function hasObjectPrototype(o) {
|
|
943
|
-
return Object.prototype.toString.call(o) === '[object Object]';
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
function last(arr) {
|
|
947
|
-
return arr[arr.length - 1];
|
|
948
|
-
}
|
|
949
|
-
function warning(cond, message) {
|
|
950
|
-
if (cond) {
|
|
951
|
-
if (typeof console !== 'undefined') console.warn(message);
|
|
952
|
-
|
|
953
|
-
try {
|
|
954
|
-
throw new Error(message);
|
|
955
|
-
} catch (_unused) {}
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
return true;
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
function isFunction(d) {
|
|
962
|
-
return typeof d === 'function';
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
function functionalUpdate(updater, previous) {
|
|
966
|
-
if (isFunction(updater)) {
|
|
967
|
-
return updater(previous);
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
return updater;
|
|
971
|
-
}
|
|
972
|
-
function pick(parent, keys) {
|
|
973
|
-
return keys.reduce((obj, key) => {
|
|
974
|
-
obj[key] = parent[key];
|
|
975
|
-
return obj;
|
|
976
|
-
}, {});
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
function joinPaths(paths) {
|
|
980
|
-
return cleanPath(paths.filter(Boolean).join('/'));
|
|
981
|
-
}
|
|
982
|
-
function cleanPath(path) {
|
|
983
|
-
// remove double slashes
|
|
984
|
-
return path.replace(/\/{2,}/g, '/');
|
|
985
|
-
}
|
|
986
|
-
function trimPathLeft(path) {
|
|
987
|
-
return path === '/' ? path : path.replace(/^\/{1,}/, '');
|
|
988
|
-
}
|
|
989
|
-
function trimPathRight(path) {
|
|
990
|
-
return path === '/' ? path : path.replace(/\/{1,}$/, '');
|
|
991
|
-
}
|
|
992
|
-
function trimPath(path) {
|
|
993
|
-
return trimPathRight(trimPathLeft(path));
|
|
994
|
-
}
|
|
995
|
-
function resolvePath(basepath, base, to) {
|
|
996
|
-
base = base.replace(new RegExp("^" + basepath), '/');
|
|
997
|
-
to = to.replace(new RegExp("^" + basepath), '/');
|
|
998
|
-
let baseSegments = parsePathname(base);
|
|
999
|
-
const toSegments = parsePathname(to);
|
|
1000
|
-
toSegments.forEach((toSegment, index) => {
|
|
1001
|
-
if (toSegment.value === '/') {
|
|
1002
|
-
if (!index) {
|
|
1003
|
-
// Leading slash
|
|
1004
|
-
baseSegments = [toSegment];
|
|
1005
|
-
} else if (index === toSegments.length - 1) {
|
|
1006
|
-
// Trailing Slash
|
|
1007
|
-
baseSegments.push(toSegment);
|
|
1008
|
-
} else ;
|
|
1009
|
-
} else if (toSegment.value === '..') {
|
|
1010
|
-
var _last;
|
|
1011
|
-
|
|
1012
|
-
// Extra trailing slash? pop it off
|
|
1013
|
-
if (baseSegments.length > 1 && ((_last = last(baseSegments)) == null ? void 0 : _last.value) === '/') {
|
|
1014
|
-
baseSegments.pop();
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
baseSegments.pop();
|
|
1018
|
-
} else if (toSegment.value === '.') {
|
|
1019
|
-
return;
|
|
1020
|
-
} else {
|
|
1021
|
-
baseSegments.push(toSegment);
|
|
1022
|
-
}
|
|
1023
|
-
});
|
|
1024
|
-
const joined = joinPaths([basepath, ...baseSegments.map(d => d.value)]);
|
|
1025
|
-
return cleanPath(joined);
|
|
1026
|
-
}
|
|
1027
|
-
function parsePathname(pathname) {
|
|
1028
|
-
if (!pathname) {
|
|
1029
|
-
return [];
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
pathname = cleanPath(pathname);
|
|
1033
|
-
const segments = [];
|
|
1034
|
-
|
|
1035
|
-
if (pathname.slice(0, 1) === '/') {
|
|
1036
|
-
pathname = pathname.substring(1);
|
|
1037
|
-
segments.push({
|
|
1038
|
-
type: 'pathname',
|
|
1039
|
-
value: '/'
|
|
1040
|
-
});
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
if (!pathname) {
|
|
1044
|
-
return segments;
|
|
1045
|
-
} // Remove empty segments and '.' segments
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
const split = pathname.split('/').filter(Boolean);
|
|
1049
|
-
segments.push(...split.map(part => {
|
|
1050
|
-
if (part.startsWith('*')) {
|
|
1051
|
-
return {
|
|
1052
|
-
type: 'wildcard',
|
|
1053
|
-
value: part
|
|
1054
|
-
};
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
if (part.charAt(0) === '$') {
|
|
1058
|
-
return {
|
|
1059
|
-
type: 'param',
|
|
1060
|
-
value: part
|
|
1061
|
-
};
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
return {
|
|
1065
|
-
type: 'pathname',
|
|
1066
|
-
value: part
|
|
1067
|
-
};
|
|
1068
|
-
}));
|
|
1069
|
-
|
|
1070
|
-
if (pathname.slice(-1) === '/') {
|
|
1071
|
-
pathname = pathname.substring(1);
|
|
1072
|
-
segments.push({
|
|
1073
|
-
type: 'pathname',
|
|
1074
|
-
value: '/'
|
|
1075
|
-
});
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
return segments;
|
|
1079
|
-
}
|
|
1080
|
-
function interpolatePath(path, params, leaveWildcard) {
|
|
1081
|
-
const interpolatedPathSegments = parsePathname(path);
|
|
1082
|
-
return joinPaths(interpolatedPathSegments.map(segment => {
|
|
1083
|
-
if (segment.value === '*' && !leaveWildcard) {
|
|
1084
|
-
return '';
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
if (segment.type === 'param') {
|
|
1088
|
-
var _segment$value$substr;
|
|
1089
|
-
|
|
1090
|
-
return (_segment$value$substr = params[segment.value.substring(1)]) != null ? _segment$value$substr : '';
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
return segment.value;
|
|
1094
|
-
}));
|
|
1095
|
-
}
|
|
1096
|
-
function matchPathname(currentPathname, matchLocation) {
|
|
1097
|
-
const pathParams = matchByPath(currentPathname, matchLocation); // const searchMatched = matchBySearch(currentLocation.search, matchLocation)
|
|
1098
|
-
|
|
1099
|
-
if (matchLocation.to && !pathParams) {
|
|
1100
|
-
return;
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
return pathParams != null ? pathParams : {};
|
|
1104
|
-
}
|
|
1105
|
-
function matchByPath(from, matchLocation) {
|
|
1106
|
-
var _matchLocation$to;
|
|
1107
|
-
|
|
1108
|
-
const baseSegments = parsePathname(from);
|
|
1109
|
-
const routeSegments = parsePathname("" + ((_matchLocation$to = matchLocation.to) != null ? _matchLocation$to : '*'));
|
|
1110
|
-
const params = {};
|
|
1111
|
-
|
|
1112
|
-
let isMatch = (() => {
|
|
1113
|
-
for (let i = 0; i < Math.max(baseSegments.length, routeSegments.length); i++) {
|
|
1114
|
-
const baseSegment = baseSegments[i];
|
|
1115
|
-
const routeSegment = routeSegments[i];
|
|
1116
|
-
const isLastRouteSegment = i === routeSegments.length - 1;
|
|
1117
|
-
const isLastBaseSegment = i === baseSegments.length - 1;
|
|
1118
|
-
|
|
1119
|
-
if (routeSegment) {
|
|
1120
|
-
if (routeSegment.type === 'wildcard') {
|
|
1121
|
-
if (baseSegment != null && baseSegment.value) {
|
|
1122
|
-
params['*'] = joinPaths(baseSegments.slice(i).map(d => d.value));
|
|
1123
|
-
return true;
|
|
1124
|
-
}
|
|
1125
|
-
|
|
1126
|
-
return false;
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
if (routeSegment.type === 'pathname') {
|
|
1130
|
-
if (routeSegment.value === '/' && !(baseSegment != null && baseSegment.value)) {
|
|
1131
|
-
return true;
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
if (baseSegment) {
|
|
1135
|
-
if (matchLocation.caseSensitive) {
|
|
1136
|
-
if (routeSegment.value !== baseSegment.value) {
|
|
1137
|
-
return false;
|
|
1138
|
-
}
|
|
1139
|
-
} else if (routeSegment.value.toLowerCase() !== baseSegment.value.toLowerCase()) {
|
|
1140
|
-
return false;
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
if (!baseSegment) {
|
|
1146
|
-
return false;
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
if (routeSegment.type === 'param') {
|
|
1150
|
-
if ((baseSegment == null ? void 0 : baseSegment.value) === '/') {
|
|
1151
|
-
return false;
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
if (baseSegment.value.charAt(0) !== '$') {
|
|
1155
|
-
params[routeSegment.value.substring(1)] = baseSegment.value;
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
if (isLastRouteSegment && !isLastBaseSegment) {
|
|
1161
|
-
return !!matchLocation.fuzzy;
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
return true;
|
|
1166
|
-
})();
|
|
1167
|
-
|
|
1168
|
-
return isMatch ? params : undefined;
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
// @ts-nocheck
|
|
1172
|
-
// qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.
|
|
1173
|
-
function encode(obj, pfx) {
|
|
1174
|
-
var k,
|
|
1175
|
-
i,
|
|
1176
|
-
tmp,
|
|
1177
|
-
str = '';
|
|
1178
|
-
|
|
1179
|
-
for (k in obj) {
|
|
1180
|
-
if ((tmp = obj[k]) !== void 0) {
|
|
1181
|
-
if (Array.isArray(tmp)) {
|
|
1182
|
-
for (i = 0; i < tmp.length; i++) {
|
|
1183
|
-
str && (str += '&');
|
|
1184
|
-
str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i]);
|
|
1185
|
-
}
|
|
1186
|
-
} else {
|
|
1187
|
-
str && (str += '&');
|
|
1188
|
-
str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp);
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
return (pfx || '') + str;
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
|
-
function toValue(mix) {
|
|
1197
|
-
if (!mix) return '';
|
|
1198
|
-
var str = decodeURIComponent(mix);
|
|
1199
|
-
if (str === 'false') return false;
|
|
1200
|
-
if (str === 'true') return true;
|
|
1201
|
-
if (str.charAt(0) === '0') return str;
|
|
1202
|
-
return +str * 0 === 0 ? +str : str;
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
function decode(str) {
|
|
1206
|
-
var tmp,
|
|
1207
|
-
k,
|
|
1208
|
-
out = {},
|
|
1209
|
-
arr = str.split('&');
|
|
1210
|
-
|
|
1211
|
-
while (tmp = arr.shift()) {
|
|
1212
|
-
tmp = tmp.split('=');
|
|
1213
|
-
k = tmp.shift();
|
|
1214
|
-
|
|
1215
|
-
if (out[k] !== void 0) {
|
|
1216
|
-
out[k] = [].concat(out[k], toValue(tmp.shift()));
|
|
1217
|
-
} else {
|
|
1218
|
-
out[k] = toValue(tmp.shift());
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
|
|
1222
|
-
return out;
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
function _extends() {
|
|
1226
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
1227
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
1228
|
-
var source = arguments[i];
|
|
1229
|
-
|
|
1230
|
-
for (var key in source) {
|
|
1231
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1232
|
-
target[key] = source[key];
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
return target;
|
|
1238
|
-
};
|
|
1239
|
-
return _extends.apply(this, arguments);
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
function createRoute(routeConfig, options, parent, router) {
|
|
1243
|
-
const {
|
|
1244
|
-
id,
|
|
1245
|
-
routeId,
|
|
1246
|
-
path: routePath,
|
|
1247
|
-
fullPath
|
|
1248
|
-
} = routeConfig;
|
|
1249
|
-
|
|
1250
|
-
const action = router.state.actions[id] || (() => {
|
|
1251
|
-
router.state.actions[id] = {
|
|
1252
|
-
submissions: [],
|
|
1253
|
-
submit: async (submission, actionOpts) => {
|
|
1254
|
-
var _actionOpts$invalidat;
|
|
1255
|
-
|
|
1256
|
-
if (!route) {
|
|
1257
|
-
return;
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
|
|
1261
|
-
|
|
1262
|
-
if (!(actionOpts != null && actionOpts.multi)) {
|
|
1263
|
-
action.submissions = action.submissions.filter(d => d.isMulti);
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
const actionState = {
|
|
1267
|
-
submittedAt: Date.now(),
|
|
1268
|
-
status: 'pending',
|
|
1269
|
-
submission,
|
|
1270
|
-
isMulti: !!(actionOpts != null && actionOpts.multi)
|
|
1271
|
-
};
|
|
1272
|
-
action.current = actionState;
|
|
1273
|
-
action.latest = actionState;
|
|
1274
|
-
action.submissions.push(actionState);
|
|
1275
|
-
router.notify();
|
|
1276
|
-
|
|
1277
|
-
try {
|
|
1278
|
-
const res = await (route.options.action == null ? void 0 : route.options.action(submission));
|
|
1279
|
-
actionState.data = res;
|
|
1280
|
-
|
|
1281
|
-
if (invalidate) {
|
|
1282
|
-
router.invalidateRoute({
|
|
1283
|
-
to: '.',
|
|
1284
|
-
fromCurrent: true
|
|
1285
|
-
});
|
|
1286
|
-
await router.reload();
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
actionState.status = 'success';
|
|
1290
|
-
return res;
|
|
1291
|
-
} catch (err) {
|
|
1292
|
-
console.error(err);
|
|
1293
|
-
actionState.error = err;
|
|
1294
|
-
actionState.status = 'error';
|
|
1295
|
-
} finally {
|
|
1296
|
-
router.notify();
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
};
|
|
1300
|
-
return router.state.actions[id];
|
|
1301
|
-
})();
|
|
1302
|
-
|
|
1303
|
-
const loader = router.state.loaders[id] || (() => {
|
|
1304
|
-
router.state.loaders[id] = {
|
|
1305
|
-
pending: [],
|
|
1306
|
-
fetch: async loaderContext => {
|
|
1307
|
-
if (!route) {
|
|
1308
|
-
return;
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
const loaderState = {
|
|
1312
|
-
loadedAt: Date.now(),
|
|
1313
|
-
loaderContext
|
|
1314
|
-
};
|
|
1315
|
-
loader.current = loaderState;
|
|
1316
|
-
loader.latest = loaderState;
|
|
1317
|
-
loader.pending.push(loaderState); // router.state = {
|
|
1318
|
-
// ...router.state,
|
|
1319
|
-
// currentAction: loaderState,
|
|
1320
|
-
// latestAction: loaderState,
|
|
1321
|
-
// }
|
|
1322
|
-
|
|
1323
|
-
router.notify();
|
|
1324
|
-
|
|
1325
|
-
try {
|
|
1326
|
-
return await (route.options.loader == null ? void 0 : route.options.loader(loaderContext));
|
|
1327
|
-
} finally {
|
|
1328
|
-
loader.pending = loader.pending.filter(d => d !== loaderState); // router.removeActionQueue.push({ loader, loaderState })
|
|
1329
|
-
|
|
1330
|
-
router.notify();
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
};
|
|
1334
|
-
return router.state.loaders[id];
|
|
1335
|
-
})();
|
|
1336
|
-
|
|
1337
|
-
let route = {
|
|
1338
|
-
routeInfo: undefined,
|
|
1339
|
-
routeId: id,
|
|
1340
|
-
routeRouteId: routeId,
|
|
1341
|
-
routePath,
|
|
1342
|
-
fullPath,
|
|
1343
|
-
options,
|
|
1344
|
-
router,
|
|
1345
|
-
childRoutes: undefined,
|
|
1346
|
-
parentRoute: parent,
|
|
1347
|
-
action,
|
|
1348
|
-
loader: loader,
|
|
1349
|
-
buildLink: options => {
|
|
1350
|
-
return router.buildLink(_extends({}, options, {
|
|
1351
|
-
from: fullPath
|
|
1352
|
-
}));
|
|
1353
|
-
},
|
|
1354
|
-
navigate: options => {
|
|
1355
|
-
return router.navigate(_extends({}, options, {
|
|
1356
|
-
from: fullPath
|
|
1357
|
-
}));
|
|
1358
|
-
},
|
|
1359
|
-
matchRoute: (matchLocation, opts) => {
|
|
1360
|
-
return router.matchRoute(_extends({}, matchLocation, {
|
|
1361
|
-
from: fullPath
|
|
1362
|
-
}), opts);
|
|
1363
|
-
}
|
|
1364
|
-
};
|
|
1365
|
-
router.options.createRoute == null ? void 0 : router.options.createRoute({
|
|
1366
|
-
router,
|
|
1367
|
-
route
|
|
1368
|
-
});
|
|
1369
|
-
return route;
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
const rootRouteId = '__root__';
|
|
1373
|
-
const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
|
|
1374
|
-
if (options === void 0) {
|
|
1375
|
-
options = {};
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
|
-
if (isRoot === void 0) {
|
|
1379
|
-
isRoot = true;
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
if (isRoot) {
|
|
1383
|
-
options.path = rootRouteId;
|
|
1384
|
-
} // Strip the root from parentIds
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
if (parentId === rootRouteId) {
|
|
1388
|
-
parentId = '';
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
let path = isRoot ? rootRouteId : options.path; // If the path is anything other than an index path, trim it up
|
|
1392
|
-
|
|
1393
|
-
if (path && path !== '/') {
|
|
1394
|
-
path = trimPath(path);
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
const routeId = path || options.id;
|
|
1398
|
-
let id = joinPaths([parentId, routeId]);
|
|
1399
|
-
|
|
1400
|
-
if (path === rootRouteId) {
|
|
1401
|
-
path = '/';
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
if (id !== rootRouteId) {
|
|
1405
|
-
id = joinPaths(['/', id]);
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
const fullPath = id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]));
|
|
1409
|
-
return {
|
|
1410
|
-
id: id,
|
|
1411
|
-
routeId: routeId,
|
|
1412
|
-
path: path,
|
|
1413
|
-
fullPath: fullPath,
|
|
1414
|
-
options: options,
|
|
1415
|
-
children,
|
|
1416
|
-
addChildren: children => createRouteConfig(options, children, false, parentId, parentPath),
|
|
1417
|
-
createRoute: childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath),
|
|
1418
|
-
generate: () => {
|
|
1419
|
-
invariant(false, "routeConfig.generate() is used by TanStack Router's file-based routing code generation and should not actually be called during runtime. ");
|
|
1420
|
-
}
|
|
1421
|
-
};
|
|
1422
|
-
};
|
|
1423
|
-
|
|
1424
|
-
const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
|
|
1425
|
-
function createRouteMatch(router, route, opts) {
|
|
1426
|
-
const routeMatch = _extends({}, route, opts, {
|
|
1427
|
-
router,
|
|
1428
|
-
routeSearch: {},
|
|
1429
|
-
search: {},
|
|
1430
|
-
childMatches: [],
|
|
1431
|
-
status: 'idle',
|
|
1432
|
-
routeLoaderData: {},
|
|
1433
|
-
loaderData: {},
|
|
1434
|
-
isFetching: false,
|
|
1435
|
-
isInvalid: false,
|
|
1436
|
-
invalidAt: Infinity,
|
|
1437
|
-
// pendingActions: [],
|
|
1438
|
-
getIsInvalid: () => {
|
|
1439
|
-
const now = Date.now();
|
|
1440
|
-
return routeMatch.isInvalid || routeMatch.invalidAt < now;
|
|
1441
|
-
},
|
|
1442
|
-
__: {
|
|
1443
|
-
abortController: new AbortController(),
|
|
1444
|
-
latestId: '',
|
|
1445
|
-
resolve: () => {},
|
|
1446
|
-
notify: () => {
|
|
1447
|
-
routeMatch.__.resolve();
|
|
1448
|
-
|
|
1449
|
-
routeMatch.router.notify();
|
|
1450
|
-
},
|
|
1451
|
-
validate: () => {
|
|
1452
|
-
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1453
|
-
|
|
1454
|
-
// Validate the search params and stabilize them
|
|
1455
|
-
const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
|
|
1456
|
-
|
|
1457
|
-
try {
|
|
1458
|
-
var _validator;
|
|
1459
|
-
|
|
1460
|
-
const prevSearch = routeMatch.routeSearch;
|
|
1461
|
-
const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
|
|
1462
|
-
let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {}); // Invalidate route matches when search param stability changes
|
|
1463
|
-
|
|
1464
|
-
if (prevSearch !== nextSearch) {
|
|
1465
|
-
routeMatch.isInvalid = true;
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
routeMatch.routeSearch = nextSearch;
|
|
1469
|
-
routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
|
|
1470
|
-
componentTypes.map(async type => {
|
|
1471
|
-
const component = routeMatch.options[type];
|
|
1472
|
-
|
|
1473
|
-
if (typeof routeMatch.__[type] !== 'function') {
|
|
1474
|
-
routeMatch.__[type] = component;
|
|
1475
|
-
}
|
|
1476
|
-
});
|
|
1477
|
-
} catch (err) {
|
|
1478
|
-
console.error(err);
|
|
1479
|
-
const error = new Error('Invalid search params found', {
|
|
1480
|
-
cause: err
|
|
1481
|
-
});
|
|
1482
|
-
error.code = 'INVALID_SEARCH_PARAMS';
|
|
1483
|
-
routeMatch.status = 'error';
|
|
1484
|
-
routeMatch.error = error; // Do not proceed with loading the route
|
|
1485
|
-
|
|
1486
|
-
return;
|
|
1487
|
-
}
|
|
1488
|
-
}
|
|
1489
|
-
},
|
|
1490
|
-
cancel: () => {
|
|
1491
|
-
var _routeMatch$__$abortC;
|
|
1492
|
-
|
|
1493
|
-
(_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
|
|
1494
|
-
},
|
|
1495
|
-
invalidate: () => {
|
|
1496
|
-
routeMatch.isInvalid = true;
|
|
1497
|
-
},
|
|
1498
|
-
hasLoaders: () => {
|
|
1499
|
-
return !!(route.options.loader || componentTypes.some(d => {
|
|
1500
|
-
var _route$options$d;
|
|
1501
|
-
|
|
1502
|
-
return (_route$options$d = route.options[d]) == null ? void 0 : _route$options$d.preload;
|
|
1503
|
-
}));
|
|
1504
|
-
},
|
|
1505
|
-
load: async loaderOpts => {
|
|
1506
|
-
const now = Date.now();
|
|
1507
|
-
const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0; // If this is a preload, add it to the preload cache
|
|
1508
|
-
|
|
1509
|
-
if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
|
|
1510
|
-
// If the match is currently active, don't preload it
|
|
1511
|
-
if (router.state.matches.find(d => d.matchId === routeMatch.matchId)) {
|
|
1512
|
-
return;
|
|
1513
|
-
}
|
|
1514
|
-
|
|
1515
|
-
router.matchCache[routeMatch.matchId] = {
|
|
1516
|
-
gc: now + loaderOpts.gcMaxAge,
|
|
1517
|
-
match: routeMatch
|
|
1518
|
-
};
|
|
1519
|
-
} // If the match is invalid, errored or idle, trigger it to load
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
|
|
1523
|
-
const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
|
|
1524
|
-
await routeMatch.fetch({
|
|
1525
|
-
maxAge
|
|
1526
|
-
});
|
|
1527
|
-
}
|
|
1528
|
-
},
|
|
1529
|
-
fetch: async opts => {
|
|
1530
|
-
const loadId = '' + Date.now() + Math.random();
|
|
1531
|
-
routeMatch.__.latestId = loadId;
|
|
1532
|
-
|
|
1533
|
-
const checkLatest = async () => {
|
|
1534
|
-
if (loadId !== routeMatch.__.latestId) {
|
|
1535
|
-
// warning(true, 'Data loader is out of date!')
|
|
1536
|
-
return new Promise(() => {});
|
|
1537
|
-
}
|
|
1538
|
-
}; // If the match was in an error state, set it
|
|
1539
|
-
// to a loading state again. Otherwise, keep it
|
|
1540
|
-
// as loading or resolved
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
if (routeMatch.status === 'idle') {
|
|
1544
|
-
routeMatch.status = 'loading';
|
|
1545
|
-
} // We started loading the route, so it's no longer invalid
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
routeMatch.isInvalid = false;
|
|
1549
|
-
routeMatch.__.loadPromise = new Promise(async resolve => {
|
|
1550
|
-
// We are now fetching, even if it's in the background of a
|
|
1551
|
-
// resolved state
|
|
1552
|
-
routeMatch.isFetching = true;
|
|
1553
|
-
routeMatch.__.resolve = resolve;
|
|
1554
|
-
|
|
1555
|
-
routeMatch.__.componentsPromise = (async () => {
|
|
1556
|
-
// then run all component and data loaders in parallel
|
|
1557
|
-
// For each component type, potentially load it asynchronously
|
|
1558
|
-
await Promise.all(componentTypes.map(async type => {
|
|
1559
|
-
var _routeMatch$__$type;
|
|
1560
|
-
|
|
1561
|
-
const component = routeMatch.options[type];
|
|
1562
|
-
|
|
1563
|
-
if ((_routeMatch$__$type = routeMatch.__[type]) != null && _routeMatch$__$type.preload) {
|
|
1564
|
-
routeMatch.__[type] = await router.options.loadComponent(component);
|
|
1565
|
-
}
|
|
1566
|
-
}));
|
|
1567
|
-
})();
|
|
1568
|
-
|
|
1569
|
-
routeMatch.__.dataPromise = Promise.resolve().then(async () => {
|
|
1570
|
-
try {
|
|
1571
|
-
var _ref, _ref2, _opts$maxAge;
|
|
1572
|
-
|
|
1573
|
-
if (routeMatch.options.loader) {
|
|
1574
|
-
const data = await router.loadMatchData(routeMatch);
|
|
1575
|
-
await checkLatest();
|
|
1576
|
-
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
routeMatch.error = undefined;
|
|
1580
|
-
routeMatch.status = 'success';
|
|
1581
|
-
routeMatch.updatedAt = Date.now();
|
|
1582
|
-
routeMatch.invalidAt = routeMatch.updatedAt + ((_ref = (_ref2 = (_opts$maxAge = opts == null ? void 0 : opts.maxAge) != null ? _opts$maxAge : routeMatch.options.loaderMaxAge) != null ? _ref2 : router.options.defaultLoaderMaxAge) != null ? _ref : 0);
|
|
1583
|
-
return routeMatch.routeLoaderData;
|
|
1584
|
-
} catch (err) {
|
|
1585
|
-
await checkLatest();
|
|
1586
|
-
|
|
1587
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1588
|
-
console.error(err);
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1591
|
-
routeMatch.error = err;
|
|
1592
|
-
routeMatch.status = 'error';
|
|
1593
|
-
routeMatch.updatedAt = Date.now();
|
|
1594
|
-
throw err;
|
|
1595
|
-
}
|
|
1596
|
-
});
|
|
1597
|
-
|
|
1598
|
-
const after = async () => {
|
|
1599
|
-
await checkLatest();
|
|
1600
|
-
routeMatch.isFetching = false;
|
|
1601
|
-
delete routeMatch.__.loadPromise;
|
|
1602
|
-
|
|
1603
|
-
routeMatch.__.notify();
|
|
1604
|
-
};
|
|
1605
|
-
|
|
1606
|
-
try {
|
|
1607
|
-
await Promise.all([routeMatch.__.componentsPromise, routeMatch.__.dataPromise.catch(() => {})]);
|
|
1608
|
-
after();
|
|
1609
|
-
} catch (_unused) {
|
|
1610
|
-
after();
|
|
1611
|
-
}
|
|
1612
|
-
});
|
|
1613
|
-
await routeMatch.__.loadPromise;
|
|
1614
|
-
await checkLatest();
|
|
1615
|
-
}
|
|
1616
|
-
});
|
|
1617
|
-
|
|
1618
|
-
if (!routeMatch.hasLoaders()) {
|
|
1619
|
-
routeMatch.status = 'success';
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
return routeMatch;
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
|
-
const defaultParseSearch = parseSearchWith(JSON.parse);
|
|
1626
|
-
const defaultStringifySearch = stringifySearchWith(JSON.stringify);
|
|
1627
|
-
function parseSearchWith(parser) {
|
|
1628
|
-
return searchStr => {
|
|
1629
|
-
if (searchStr.substring(0, 1) === '?') {
|
|
1630
|
-
searchStr = searchStr.substring(1);
|
|
1631
|
-
}
|
|
1632
|
-
|
|
1633
|
-
let query = decode(searchStr); // Try to parse any query params that might be json
|
|
1634
|
-
|
|
1635
|
-
for (let key in query) {
|
|
1636
|
-
const value = query[key];
|
|
1637
|
-
|
|
1638
|
-
if (typeof value === 'string') {
|
|
1639
|
-
try {
|
|
1640
|
-
query[key] = parser(value);
|
|
1641
|
-
} catch (err) {//
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
|
|
1646
|
-
return query;
|
|
1647
|
-
};
|
|
1648
|
-
}
|
|
1649
|
-
function stringifySearchWith(stringify) {
|
|
1650
|
-
return search => {
|
|
1651
|
-
search = _extends({}, search);
|
|
1652
|
-
|
|
1653
|
-
if (search) {
|
|
1654
|
-
Object.keys(search).forEach(key => {
|
|
1655
|
-
const val = search[key];
|
|
1656
|
-
|
|
1657
|
-
if (typeof val === 'undefined' || val === undefined) {
|
|
1658
|
-
delete search[key];
|
|
1659
|
-
} else if (val && typeof val === 'object' && val !== null) {
|
|
1660
|
-
try {
|
|
1661
|
-
search[key] = stringify(val);
|
|
1662
|
-
} catch (err) {// silent
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
});
|
|
1666
|
-
}
|
|
1667
|
-
|
|
1668
|
-
const searchStr = encode(search).toString();
|
|
1669
|
-
return searchStr ? "?" + searchStr : '';
|
|
1670
|
-
};
|
|
1671
|
-
}
|
|
1672
|
-
|
|
1673
|
-
var _window$document;
|
|
1674
|
-
// Detect if we're in the DOM
|
|
1675
|
-
const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement); // This is the default history object if none is defined
|
|
1676
|
-
|
|
1677
|
-
const createDefaultHistory = () => isServer ? createMemoryHistory() : createBrowserHistory();
|
|
1678
|
-
|
|
1679
|
-
function getInitialRouterState() {
|
|
1680
|
-
return {
|
|
1681
|
-
status: 'idle',
|
|
1682
|
-
location: null,
|
|
1683
|
-
matches: [],
|
|
1684
|
-
actions: {},
|
|
1685
|
-
loaders: {},
|
|
1686
|
-
lastUpdated: Date.now(),
|
|
1687
|
-
isFetching: false,
|
|
1688
|
-
isPreloading: false
|
|
1689
|
-
};
|
|
1690
|
-
}
|
|
1691
|
-
|
|
1692
|
-
function createRouter(userOptions) {
|
|
1693
|
-
var _userOptions$stringif, _userOptions$parseSea;
|
|
1694
|
-
|
|
1695
|
-
const history = (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory();
|
|
1696
|
-
|
|
1697
|
-
const originalOptions = _extends({
|
|
1698
|
-
defaultLoaderGcMaxAge: 5 * 60 * 1000,
|
|
1699
|
-
defaultLoaderMaxAge: 0,
|
|
1700
|
-
defaultPreloadMaxAge: 2000,
|
|
1701
|
-
defaultPreloadDelay: 50
|
|
1702
|
-
}, userOptions, {
|
|
1703
|
-
stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
|
|
1704
|
-
parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
|
|
1705
|
-
});
|
|
1706
|
-
|
|
1707
|
-
let router = {
|
|
1708
|
-
types: undefined,
|
|
1709
|
-
// public api
|
|
1710
|
-
history,
|
|
1711
|
-
options: originalOptions,
|
|
1712
|
-
listeners: [],
|
|
1713
|
-
// Resolved after construction
|
|
1714
|
-
context: {},
|
|
1715
|
-
basepath: '',
|
|
1716
|
-
routeTree: undefined,
|
|
1717
|
-
routesById: {},
|
|
1718
|
-
location: undefined,
|
|
1719
|
-
//
|
|
1720
|
-
navigationPromise: Promise.resolve(),
|
|
1721
|
-
resolveNavigation: () => {},
|
|
1722
|
-
matchCache: {},
|
|
1723
|
-
state: getInitialRouterState(),
|
|
1724
|
-
reset: () => {
|
|
1725
|
-
router.state = getInitialRouterState();
|
|
1726
|
-
router.notify();
|
|
1727
|
-
},
|
|
1728
|
-
startedLoadingAt: Date.now(),
|
|
1729
|
-
subscribe: listener => {
|
|
1730
|
-
router.listeners.push(listener);
|
|
1731
|
-
return () => {
|
|
1732
|
-
router.listeners = router.listeners.filter(x => x !== listener);
|
|
1733
|
-
};
|
|
1734
|
-
},
|
|
1735
|
-
getRoute: id => {
|
|
1736
|
-
return router.routesById[id];
|
|
1737
|
-
},
|
|
1738
|
-
notify: () => {
|
|
1739
|
-
const isFetching = router.state.status === 'loading' || router.state.matches.some(d => d.isFetching);
|
|
1740
|
-
const isPreloading = Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId));
|
|
1741
|
-
|
|
1742
|
-
if (router.state.isFetching !== isFetching || router.state.isPreloading !== isPreloading) {
|
|
1743
|
-
router.state = _extends({}, router.state, {
|
|
1744
|
-
isFetching,
|
|
1745
|
-
isPreloading
|
|
1746
|
-
});
|
|
1747
|
-
}
|
|
1748
|
-
|
|
1749
|
-
cascadeLoaderData(router.state.matches);
|
|
1750
|
-
router.listeners.forEach(listener => listener(router));
|
|
1751
|
-
},
|
|
1752
|
-
dehydrateState: () => {
|
|
1753
|
-
return _extends({}, pick(router.state, ['status', 'location', 'lastUpdated']), {
|
|
1754
|
-
matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
|
|
1755
|
-
});
|
|
1756
|
-
},
|
|
1757
|
-
hydrateState: dehydratedState => {
|
|
1758
|
-
// Match the routes
|
|
1759
|
-
const matches = router.matchRoutes(router.location.pathname, {
|
|
1760
|
-
strictParseParams: true
|
|
1761
|
-
});
|
|
1762
|
-
matches.forEach((match, index) => {
|
|
1763
|
-
const dehydratedMatch = dehydratedState.matches[index];
|
|
1764
|
-
invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
|
|
1765
|
-
Object.assign(match, dehydratedMatch);
|
|
1766
|
-
});
|
|
1767
|
-
matches.forEach(match => match.__.validate());
|
|
1768
|
-
router.state = _extends({}, router.state, dehydratedState, {
|
|
1769
|
-
matches
|
|
1770
|
-
});
|
|
1771
|
-
},
|
|
1772
|
-
mount: () => {
|
|
1773
|
-
const next = router.__.buildLocation({
|
|
1774
|
-
to: '.',
|
|
1775
|
-
search: true,
|
|
1776
|
-
hash: true
|
|
1777
|
-
}); // If the current location isn't updated, trigger a navigation
|
|
1778
|
-
// to the current location. Otherwise, load the current location.
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
if (next.href !== router.location.href) {
|
|
1782
|
-
router.__.commitLocation(next, true);
|
|
1783
|
-
}
|
|
1784
|
-
|
|
1785
|
-
if (!router.state.matches.length) {
|
|
1786
|
-
router.load();
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1789
|
-
const unsub = router.history.listen(event => {
|
|
1790
|
-
router.load(router.__.parseLocation(event.location, router.location));
|
|
1791
|
-
}); // addEventListener does not exist in React Native, but window does
|
|
1792
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1793
|
-
|
|
1794
|
-
if (!isServer && window.addEventListener) {
|
|
1795
|
-
// Listen to visibillitychange and focus
|
|
1796
|
-
window.addEventListener('visibilitychange', router.onFocus, false);
|
|
1797
|
-
window.addEventListener('focus', router.onFocus, false);
|
|
1798
|
-
}
|
|
1799
|
-
|
|
1800
|
-
return () => {
|
|
1801
|
-
unsub();
|
|
1802
|
-
|
|
1803
|
-
if (!isServer && window.removeEventListener) {
|
|
1804
|
-
// Be sure to unsubscribe if a new handler is set
|
|
1805
|
-
window.removeEventListener('visibilitychange', router.onFocus);
|
|
1806
|
-
window.removeEventListener('focus', router.onFocus);
|
|
1807
|
-
}
|
|
1808
|
-
};
|
|
1809
|
-
},
|
|
1810
|
-
onFocus: () => {
|
|
1811
|
-
router.load();
|
|
1812
|
-
},
|
|
1813
|
-
update: opts => {
|
|
1814
|
-
const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
|
|
1815
|
-
|
|
1816
|
-
if (!router.location || newHistory) {
|
|
1817
|
-
if (opts != null && opts.history) {
|
|
1818
|
-
router.history = opts.history;
|
|
1819
|
-
}
|
|
1820
|
-
|
|
1821
|
-
router.location = router.__.parseLocation(router.history.location);
|
|
1822
|
-
router.state.location = router.location;
|
|
1823
|
-
}
|
|
1824
|
-
|
|
1825
|
-
Object.assign(router.options, opts);
|
|
1826
|
-
const {
|
|
1827
|
-
basepath,
|
|
1828
|
-
routeConfig
|
|
1829
|
-
} = router.options;
|
|
1830
|
-
router.basepath = cleanPath("/" + (basepath != null ? basepath : ''));
|
|
1831
|
-
|
|
1832
|
-
if (routeConfig) {
|
|
1833
|
-
router.routesById = {};
|
|
1834
|
-
router.routeTree = router.__.buildRouteTree(routeConfig);
|
|
1835
|
-
}
|
|
1836
|
-
|
|
1837
|
-
return router;
|
|
1838
|
-
},
|
|
1839
|
-
cancelMatches: () => {
|
|
1840
|
-
var _router$state$pending, _router$state$pending2;
|
|
1841
|
-
[...router.state.matches, ...((_router$state$pending = (_router$state$pending2 = router.state.pending) == null ? void 0 : _router$state$pending2.matches) != null ? _router$state$pending : [])].forEach(match => {
|
|
1842
|
-
match.cancel();
|
|
1843
|
-
});
|
|
1844
|
-
},
|
|
1845
|
-
load: async next => {
|
|
1846
|
-
const id = Math.random();
|
|
1847
|
-
router.startedLoadingAt = id;
|
|
1848
|
-
|
|
1849
|
-
if (next) {
|
|
1850
|
-
// Ingest the new location
|
|
1851
|
-
router.location = next;
|
|
1852
|
-
} // Cancel any pending matches
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
router.cancelMatches(); // Match the routes
|
|
1856
|
-
|
|
1857
|
-
const matches = router.matchRoutes(router.location.pathname, {
|
|
1858
|
-
strictParseParams: true
|
|
1859
|
-
}); // Check if each match middleware to see if the route can be accessed
|
|
1860
|
-
|
|
1861
|
-
try {
|
|
1862
|
-
await Promise.all(matches.map(match => match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
|
|
1863
|
-
context: router.context
|
|
1864
|
-
})));
|
|
1865
|
-
} catch (err) {
|
|
1866
|
-
if (err != null && err.then) {
|
|
1867
|
-
await new Promise(() => {});
|
|
1868
|
-
}
|
|
1869
|
-
|
|
1870
|
-
throw err;
|
|
1871
|
-
}
|
|
1872
|
-
|
|
1873
|
-
if (typeof document !== 'undefined') {
|
|
1874
|
-
router.state = _extends({}, router.state, {
|
|
1875
|
-
pending: {
|
|
1876
|
-
matches: matches,
|
|
1877
|
-
location: router.location
|
|
1878
|
-
},
|
|
1879
|
-
status: 'loading'
|
|
1880
|
-
});
|
|
1881
|
-
} else {
|
|
1882
|
-
router.state = _extends({}, router.state, {
|
|
1883
|
-
matches: matches,
|
|
1884
|
-
location: router.location,
|
|
1885
|
-
status: 'loading'
|
|
1886
|
-
});
|
|
1887
|
-
}
|
|
1888
|
-
|
|
1889
|
-
router.notify(); // Load the matches
|
|
1890
|
-
|
|
1891
|
-
await router.loadMatches(matches);
|
|
1892
|
-
|
|
1893
|
-
if (router.startedLoadingAt !== id) {
|
|
1894
|
-
// Ignore side-effects of match loading
|
|
1895
|
-
return router.navigationPromise;
|
|
1896
|
-
}
|
|
1897
|
-
|
|
1898
|
-
const previousMatches = router.state.matches;
|
|
1899
|
-
const exiting = [],
|
|
1900
|
-
staying = [];
|
|
1901
|
-
previousMatches.forEach(d => {
|
|
1902
|
-
if (matches.find(dd => dd.matchId === d.matchId)) {
|
|
1903
|
-
staying.push(d);
|
|
1904
|
-
} else {
|
|
1905
|
-
exiting.push(d);
|
|
1906
|
-
}
|
|
1907
|
-
});
|
|
1908
|
-
const entering = matches.filter(d => {
|
|
1909
|
-
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
1910
|
-
});
|
|
1911
|
-
const now = Date.now();
|
|
1912
|
-
exiting.forEach(d => {
|
|
1913
|
-
var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
|
|
1914
|
-
|
|
1915
|
-
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
1916
|
-
params: d.params,
|
|
1917
|
-
search: d.routeSearch
|
|
1918
|
-
}); // Clear idle error states when match leaves
|
|
1919
|
-
|
|
1920
|
-
if (d.status === 'error' && !d.isFetching) {
|
|
1921
|
-
d.status = 'idle';
|
|
1922
|
-
d.error = undefined;
|
|
1923
|
-
}
|
|
1924
|
-
|
|
1925
|
-
const gc = Math.max((_ref = (_d$options$loaderGcMa = d.options.loaderGcMaxAge) != null ? _d$options$loaderGcMa : router.options.defaultLoaderGcMaxAge) != null ? _ref : 0, (_ref2 = (_d$options$loaderMaxA = d.options.loaderMaxAge) != null ? _d$options$loaderMaxA : router.options.defaultLoaderMaxAge) != null ? _ref2 : 0);
|
|
1926
|
-
|
|
1927
|
-
if (gc > 0) {
|
|
1928
|
-
router.matchCache[d.matchId] = {
|
|
1929
|
-
gc: gc == Infinity ? Number.MAX_SAFE_INTEGER : now + gc,
|
|
1930
|
-
match: d
|
|
1931
|
-
};
|
|
1932
|
-
}
|
|
1933
|
-
});
|
|
1934
|
-
staying.forEach(d => {
|
|
1935
|
-
d.options.onTransition == null ? void 0 : d.options.onTransition({
|
|
1936
|
-
params: d.params,
|
|
1937
|
-
search: d.routeSearch
|
|
1938
|
-
});
|
|
1939
|
-
});
|
|
1940
|
-
entering.forEach(d => {
|
|
1941
|
-
d.__.onExit = d.options.onLoaded == null ? void 0 : d.options.onLoaded({
|
|
1942
|
-
params: d.params,
|
|
1943
|
-
search: d.search
|
|
1944
|
-
});
|
|
1945
|
-
delete router.matchCache[d.matchId];
|
|
1946
|
-
});
|
|
1947
|
-
|
|
1948
|
-
if (router.startedLoadingAt !== id) {
|
|
1949
|
-
// Ignore side-effects of match loading
|
|
1950
|
-
return;
|
|
1951
|
-
}
|
|
1952
|
-
|
|
1953
|
-
matches.forEach(match => {
|
|
1954
|
-
// Clear actions
|
|
1955
|
-
if (match.action) {
|
|
1956
|
-
match.action.current = undefined;
|
|
1957
|
-
match.action.submissions = [];
|
|
1958
|
-
}
|
|
1959
|
-
});
|
|
1960
|
-
router.state = _extends({}, router.state, {
|
|
1961
|
-
location: router.location,
|
|
1962
|
-
matches,
|
|
1963
|
-
pending: undefined,
|
|
1964
|
-
status: 'idle'
|
|
1965
|
-
});
|
|
1966
|
-
router.notify();
|
|
1967
|
-
router.resolveNavigation();
|
|
1968
|
-
},
|
|
1969
|
-
cleanMatchCache: () => {
|
|
1970
|
-
const now = Date.now();
|
|
1971
|
-
Object.keys(router.matchCache).forEach(matchId => {
|
|
1972
|
-
const entry = router.matchCache[matchId]; // Don't remove loading matches
|
|
1973
|
-
|
|
1974
|
-
if (entry.match.status === 'loading') {
|
|
1975
|
-
return;
|
|
1976
|
-
} // Do not remove successful matches that are still valid
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
if (entry.gc > 0 && entry.gc > now) {
|
|
1980
|
-
return;
|
|
1981
|
-
} // Everything else gets removed
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
delete router.matchCache[matchId];
|
|
1985
|
-
});
|
|
1986
|
-
},
|
|
1987
|
-
loadRoute: async function loadRoute(navigateOpts) {
|
|
1988
|
-
if (navigateOpts === void 0) {
|
|
1989
|
-
navigateOpts = router.location;
|
|
1990
|
-
}
|
|
1991
|
-
|
|
1992
|
-
const next = router.buildNext(navigateOpts);
|
|
1993
|
-
const matches = router.matchRoutes(next.pathname, {
|
|
1994
|
-
strictParseParams: true
|
|
1995
|
-
});
|
|
1996
|
-
await router.loadMatches(matches);
|
|
1997
|
-
return matches;
|
|
1998
|
-
},
|
|
1999
|
-
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
2000
|
-
var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
|
|
2001
|
-
|
|
2002
|
-
if (navigateOpts === void 0) {
|
|
2003
|
-
navigateOpts = router.location;
|
|
2004
|
-
}
|
|
2005
|
-
|
|
2006
|
-
const next = router.buildNext(navigateOpts);
|
|
2007
|
-
const matches = router.matchRoutes(next.pathname, {
|
|
2008
|
-
strictParseParams: true
|
|
2009
|
-
});
|
|
2010
|
-
await router.loadMatches(matches, {
|
|
2011
|
-
preload: true,
|
|
2012
|
-
maxAge: (_ref3 = (_ref4 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref4 : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0,
|
|
2013
|
-
gcMaxAge: (_ref5 = (_ref6 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref6 : router.options.defaultLoaderGcMaxAge) != null ? _ref5 : 0
|
|
2014
|
-
});
|
|
2015
|
-
return matches;
|
|
2016
|
-
},
|
|
2017
|
-
matchRoutes: (pathname, opts) => {
|
|
2018
|
-
var _router$state$pending3, _router$state$pending4;
|
|
2019
|
-
|
|
2020
|
-
router.cleanMatchCache();
|
|
2021
|
-
const matches = [];
|
|
2022
|
-
|
|
2023
|
-
if (!router.routeTree) {
|
|
2024
|
-
return matches;
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
|
-
const existingMatches = [...router.state.matches, ...((_router$state$pending3 = (_router$state$pending4 = router.state.pending) == null ? void 0 : _router$state$pending4.matches) != null ? _router$state$pending3 : [])];
|
|
2028
|
-
|
|
2029
|
-
const recurse = async routes => {
|
|
2030
|
-
var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
|
|
2031
|
-
|
|
2032
|
-
const parentMatch = last(matches);
|
|
2033
|
-
let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
|
|
2034
|
-
const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
|
|
2035
|
-
let foundRoutes = [];
|
|
2036
|
-
|
|
2037
|
-
const findMatchInRoutes = (parentRoutes, routes) => {
|
|
2038
|
-
routes.some(route => {
|
|
2039
|
-
var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
|
|
2040
|
-
|
|
2041
|
-
if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
|
|
2042
|
-
return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
|
|
2043
|
-
}
|
|
2044
|
-
|
|
2045
|
-
const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
|
|
2046
|
-
const matchParams = matchPathname(pathname, {
|
|
2047
|
-
to: route.fullPath,
|
|
2048
|
-
fuzzy,
|
|
2049
|
-
caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
|
|
2050
|
-
});
|
|
2051
|
-
|
|
2052
|
-
if (matchParams) {
|
|
2053
|
-
let parsedParams;
|
|
2054
|
-
|
|
2055
|
-
try {
|
|
2056
|
-
var _route$options$parseP;
|
|
2057
|
-
|
|
2058
|
-
parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
|
|
2059
|
-
} catch (err) {
|
|
2060
|
-
if (opts != null && opts.strictParseParams) {
|
|
2061
|
-
throw err;
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
|
|
2065
|
-
params = _extends({}, params, parsedParams);
|
|
2066
|
-
}
|
|
2067
|
-
|
|
2068
|
-
if (!!matchParams) {
|
|
2069
|
-
foundRoutes = [...parentRoutes, route];
|
|
2070
|
-
}
|
|
2071
|
-
|
|
2072
|
-
return !!foundRoutes.length;
|
|
2073
|
-
});
|
|
2074
|
-
return !!foundRoutes.length;
|
|
2075
|
-
};
|
|
2076
|
-
|
|
2077
|
-
findMatchInRoutes([], filteredRoutes);
|
|
2078
|
-
|
|
2079
|
-
if (!foundRoutes.length) {
|
|
2080
|
-
return;
|
|
2081
|
-
}
|
|
2082
|
-
|
|
2083
|
-
foundRoutes.forEach(foundRoute => {
|
|
2084
|
-
var _router$matchCache$ma;
|
|
2085
|
-
|
|
2086
|
-
const interpolatedPath = interpolatePath(foundRoute.routePath, params);
|
|
2087
|
-
const matchId = interpolatePath(foundRoute.routeId, params, true);
|
|
2088
|
-
const match = existingMatches.find(d => d.matchId === matchId) || ((_router$matchCache$ma = router.matchCache[matchId]) == null ? void 0 : _router$matchCache$ma.match) || createRouteMatch(router, foundRoute, {
|
|
2089
|
-
parentMatch,
|
|
2090
|
-
matchId,
|
|
2091
|
-
params,
|
|
2092
|
-
pathname: joinPaths([pathname, interpolatedPath])
|
|
2093
|
-
});
|
|
2094
|
-
matches.push(match);
|
|
2095
|
-
});
|
|
2096
|
-
const foundRoute = last(foundRoutes);
|
|
2097
|
-
|
|
2098
|
-
if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
|
|
2099
|
-
recurse(foundRoute.childRoutes);
|
|
2100
|
-
}
|
|
2101
|
-
};
|
|
2102
|
-
|
|
2103
|
-
recurse([router.routeTree]);
|
|
2104
|
-
cascadeLoaderData(matches);
|
|
2105
|
-
return matches;
|
|
2106
|
-
},
|
|
2107
|
-
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
2108
|
-
const matchPromises = resolvedMatches.map(async match => {
|
|
2109
|
-
// Validate the match (loads search params etc)
|
|
2110
|
-
match.__.validate();
|
|
2111
|
-
|
|
2112
|
-
match.load(loaderOpts);
|
|
2113
|
-
const search = match.search;
|
|
2114
|
-
|
|
2115
|
-
if (search.__data && search.__data.matchId !== match.matchId) {
|
|
2116
|
-
return;
|
|
2117
|
-
}
|
|
2118
|
-
|
|
2119
|
-
if (match.__.loadPromise) {
|
|
2120
|
-
// Wait for the first sign of activity from the match
|
|
2121
|
-
await match.__.loadPromise;
|
|
2122
|
-
}
|
|
2123
|
-
});
|
|
2124
|
-
router.notify();
|
|
2125
|
-
await Promise.all(matchPromises);
|
|
2126
|
-
},
|
|
2127
|
-
loadMatchData: async routeMatch => {
|
|
2128
|
-
if (isServer || !router.options.useServerData) {
|
|
2129
|
-
var _await$routeMatch$opt;
|
|
2130
|
-
|
|
2131
|
-
return (_await$routeMatch$opt = await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
|
|
2132
|
-
// parentLoaderPromise: routeMatch.parentMatch?.__.dataPromise,
|
|
2133
|
-
params: routeMatch.params,
|
|
2134
|
-
search: routeMatch.routeSearch,
|
|
2135
|
-
signal: routeMatch.__.abortController.signal
|
|
2136
|
-
}))) != null ? _await$routeMatch$opt : {};
|
|
2137
|
-
} else {
|
|
2138
|
-
const next = router.buildNext({
|
|
2139
|
-
to: '.',
|
|
2140
|
-
search: d => _extends({}, d != null ? d : {}, {
|
|
2141
|
-
__data: {
|
|
2142
|
-
matchId: routeMatch.matchId
|
|
2143
|
-
}
|
|
2144
|
-
})
|
|
2145
|
-
});
|
|
2146
|
-
const res = await fetch(next.href, {
|
|
2147
|
-
method: 'GET' // signal: routeMatch.__.abortController.signal,
|
|
2148
|
-
|
|
2149
|
-
});
|
|
2150
|
-
|
|
2151
|
-
if (res.ok) {
|
|
2152
|
-
return res.json();
|
|
2153
|
-
}
|
|
2154
|
-
|
|
2155
|
-
throw new Error('Failed to fetch match data');
|
|
2156
|
-
}
|
|
2157
|
-
},
|
|
2158
|
-
invalidateRoute: opts => {
|
|
2159
|
-
var _router$state$pending5, _router$state$pending6;
|
|
2160
|
-
|
|
2161
|
-
const next = router.buildNext(opts);
|
|
2162
|
-
const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
|
|
2163
|
-
[...router.state.matches, ...((_router$state$pending5 = (_router$state$pending6 = router.state.pending) == null ? void 0 : _router$state$pending6.matches) != null ? _router$state$pending5 : [])].forEach(match => {
|
|
2164
|
-
if (unloadedMatchIds.includes(match.matchId)) {
|
|
2165
|
-
match.invalidate();
|
|
2166
|
-
}
|
|
2167
|
-
});
|
|
2168
|
-
},
|
|
2169
|
-
reload: () => router.__.navigate({
|
|
2170
|
-
fromCurrent: true,
|
|
2171
|
-
replace: true,
|
|
2172
|
-
search: true
|
|
2173
|
-
}),
|
|
2174
|
-
resolvePath: (from, path) => {
|
|
2175
|
-
return resolvePath(router.basepath, from, cleanPath(path));
|
|
2176
|
-
},
|
|
2177
|
-
matchRoute: (location, opts) => {
|
|
2178
|
-
var _location$from;
|
|
2179
|
-
|
|
2180
|
-
// const location = router.buildNext(opts)
|
|
2181
|
-
location = _extends({}, location, {
|
|
2182
|
-
to: location.to ? router.resolvePath((_location$from = location.from) != null ? _location$from : '', location.to) : undefined
|
|
2183
|
-
});
|
|
2184
|
-
const next = router.buildNext(location);
|
|
2185
|
-
|
|
2186
|
-
if (opts != null && opts.pending) {
|
|
2187
|
-
var _router$state$pending7;
|
|
2188
|
-
|
|
2189
|
-
if (!((_router$state$pending7 = router.state.pending) != null && _router$state$pending7.location)) {
|
|
2190
|
-
return false;
|
|
2191
|
-
}
|
|
2192
|
-
|
|
2193
|
-
return !!matchPathname(router.state.pending.location.pathname, _extends({}, opts, {
|
|
2194
|
-
to: next.pathname
|
|
2195
|
-
}));
|
|
2196
|
-
}
|
|
2197
|
-
|
|
2198
|
-
return !!matchPathname(router.state.location.pathname, _extends({}, opts, {
|
|
2199
|
-
to: next.pathname
|
|
2200
|
-
}));
|
|
2201
|
-
},
|
|
2202
|
-
navigate: async _ref7 => {
|
|
2203
|
-
let {
|
|
2204
|
-
from,
|
|
2205
|
-
to = '.',
|
|
2206
|
-
search,
|
|
2207
|
-
hash,
|
|
2208
|
-
replace,
|
|
2209
|
-
params
|
|
2210
|
-
} = _ref7;
|
|
2211
|
-
// If this link simply reloads the current route,
|
|
2212
|
-
// make sure it has a new key so it will trigger a data refresh
|
|
2213
|
-
// If this `to` is a valid external URL, return
|
|
2214
|
-
// null for LinkUtils
|
|
2215
|
-
const toString = String(to);
|
|
2216
|
-
const fromString = String(from);
|
|
2217
|
-
let isExternal;
|
|
2218
|
-
|
|
2219
|
-
try {
|
|
2220
|
-
new URL("" + toString);
|
|
2221
|
-
isExternal = true;
|
|
2222
|
-
} catch (e) {}
|
|
2223
|
-
|
|
2224
|
-
invariant(!isExternal, 'Attempting to navigate to external url with router.navigate!');
|
|
2225
|
-
return router.__.navigate({
|
|
2226
|
-
from: fromString,
|
|
2227
|
-
to: toString,
|
|
2228
|
-
search,
|
|
2229
|
-
hash,
|
|
2230
|
-
replace,
|
|
2231
|
-
params
|
|
2232
|
-
});
|
|
2233
|
-
},
|
|
2234
|
-
buildLink: _ref8 => {
|
|
2235
|
-
var _preload, _ref9;
|
|
2236
|
-
|
|
2237
|
-
let {
|
|
2238
|
-
from,
|
|
2239
|
-
to = '.',
|
|
2240
|
-
search,
|
|
2241
|
-
params,
|
|
2242
|
-
hash,
|
|
2243
|
-
target,
|
|
2244
|
-
replace,
|
|
2245
|
-
activeOptions,
|
|
2246
|
-
preload,
|
|
2247
|
-
preloadMaxAge: userPreloadMaxAge,
|
|
2248
|
-
preloadGcMaxAge: userPreloadGcMaxAge,
|
|
2249
|
-
preloadDelay: userPreloadDelay,
|
|
2250
|
-
disabled
|
|
2251
|
-
} = _ref8;
|
|
2252
|
-
|
|
2253
|
-
// If this link simply reloads the current route,
|
|
2254
|
-
// make sure it has a new key so it will trigger a data refresh
|
|
2255
|
-
// If this `to` is a valid external URL, return
|
|
2256
|
-
// null for LinkUtils
|
|
2257
|
-
try {
|
|
2258
|
-
new URL("" + to);
|
|
2259
|
-
return {
|
|
2260
|
-
type: 'external',
|
|
2261
|
-
href: to
|
|
2262
|
-
};
|
|
2263
|
-
} catch (e) {}
|
|
2264
|
-
|
|
2265
|
-
const nextOpts = {
|
|
2266
|
-
from,
|
|
2267
|
-
to,
|
|
2268
|
-
search,
|
|
2269
|
-
params,
|
|
2270
|
-
hash,
|
|
2271
|
-
replace
|
|
2272
|
-
};
|
|
2273
|
-
const next = router.buildNext(nextOpts);
|
|
2274
|
-
preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
|
|
2275
|
-
const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0; // Compare path/hash for matches
|
|
2276
|
-
|
|
2277
|
-
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
2278
|
-
const currentPathSplit = router.state.location.pathname.split('/');
|
|
2279
|
-
const nextPathSplit = next.pathname.split('/');
|
|
2280
|
-
const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
|
|
2281
|
-
const hashIsEqual = router.state.location.hash === next.hash; // Combine the matches based on user options
|
|
2282
|
-
|
|
2283
|
-
const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
|
|
2284
|
-
const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true; // The final "active" test
|
|
2285
|
-
|
|
2286
|
-
const isActive = pathTest && hashTest; // The click handler
|
|
2287
|
-
|
|
2288
|
-
const handleClick = e => {
|
|
2289
|
-
if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
|
|
2290
|
-
e.preventDefault();
|
|
2291
|
-
|
|
2292
|
-
if (pathIsEqual && !search && !hash) {
|
|
2293
|
-
router.invalidateRoute(nextOpts);
|
|
2294
|
-
} // All is well? Navigate!)
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
router.__.navigate(nextOpts);
|
|
2298
|
-
}
|
|
2299
|
-
}; // The click handler
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
const handleFocus = e => {
|
|
2303
|
-
if (preload) {
|
|
2304
|
-
router.preloadRoute(nextOpts, {
|
|
2305
|
-
maxAge: userPreloadMaxAge,
|
|
2306
|
-
gcMaxAge: userPreloadGcMaxAge
|
|
2307
|
-
});
|
|
2308
|
-
}
|
|
2309
|
-
};
|
|
2310
|
-
|
|
2311
|
-
const handleEnter = e => {
|
|
2312
|
-
const target = e.target || {};
|
|
2313
|
-
|
|
2314
|
-
if (preload) {
|
|
2315
|
-
if (target.preloadTimeout) {
|
|
2316
|
-
return;
|
|
2317
|
-
}
|
|
2318
|
-
|
|
2319
|
-
target.preloadTimeout = setTimeout(() => {
|
|
2320
|
-
target.preloadTimeout = null;
|
|
2321
|
-
router.preloadRoute(nextOpts, {
|
|
2322
|
-
maxAge: userPreloadMaxAge,
|
|
2323
|
-
gcMaxAge: userPreloadGcMaxAge
|
|
2324
|
-
});
|
|
2325
|
-
}, preloadDelay);
|
|
2326
|
-
}
|
|
2327
|
-
};
|
|
2328
|
-
|
|
2329
|
-
const handleLeave = e => {
|
|
2330
|
-
const target = e.target || {};
|
|
2331
|
-
|
|
2332
|
-
if (target.preloadTimeout) {
|
|
2333
|
-
clearTimeout(target.preloadTimeout);
|
|
2334
|
-
target.preloadTimeout = null;
|
|
2335
|
-
}
|
|
2336
|
-
};
|
|
2337
|
-
|
|
2338
|
-
return {
|
|
2339
|
-
type: 'internal',
|
|
2340
|
-
next,
|
|
2341
|
-
handleFocus,
|
|
2342
|
-
handleClick,
|
|
2343
|
-
handleEnter,
|
|
2344
|
-
handleLeave,
|
|
2345
|
-
isActive,
|
|
2346
|
-
disabled
|
|
2347
|
-
};
|
|
2348
|
-
},
|
|
2349
|
-
buildNext: opts => {
|
|
2350
|
-
const next = router.__.buildLocation(opts);
|
|
2351
|
-
|
|
2352
|
-
const matches = router.matchRoutes(next.pathname);
|
|
2353
|
-
|
|
2354
|
-
const __preSearchFilters = matches.map(match => {
|
|
2355
|
-
var _match$options$preSea;
|
|
2356
|
-
|
|
2357
|
-
return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
|
|
2358
|
-
}).flat().filter(Boolean);
|
|
2359
|
-
|
|
2360
|
-
const __postSearchFilters = matches.map(match => {
|
|
2361
|
-
var _match$options$postSe;
|
|
2362
|
-
|
|
2363
|
-
return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
|
|
2364
|
-
}).flat().filter(Boolean);
|
|
2365
|
-
|
|
2366
|
-
return router.__.buildLocation(_extends({}, opts, {
|
|
2367
|
-
__preSearchFilters,
|
|
2368
|
-
__postSearchFilters
|
|
2369
|
-
}));
|
|
2370
|
-
},
|
|
2371
|
-
__: {
|
|
2372
|
-
buildRouteTree: rootRouteConfig => {
|
|
2373
|
-
const recurseRoutes = (routeConfigs, parent) => {
|
|
2374
|
-
return routeConfigs.map(routeConfig => {
|
|
2375
|
-
const routeOptions = routeConfig.options;
|
|
2376
|
-
const route = createRoute(routeConfig, routeOptions, parent, router);
|
|
2377
|
-
const existingRoute = router.routesById[route.routeId];
|
|
2378
|
-
|
|
2379
|
-
if (existingRoute) {
|
|
2380
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2381
|
-
console.warn("Duplicate routes found with id: " + String(route.routeId), router.routesById, route);
|
|
2382
|
-
}
|
|
2383
|
-
|
|
2384
|
-
throw new Error();
|
|
2385
|
-
}
|
|
2386
|
-
router.routesById[route.routeId] = route;
|
|
2387
|
-
const children = routeConfig.children;
|
|
2388
|
-
route.childRoutes = children != null && children.length ? recurseRoutes(children, route) : undefined;
|
|
2389
|
-
return route;
|
|
2390
|
-
});
|
|
2391
|
-
};
|
|
2392
|
-
|
|
2393
|
-
const routes = recurseRoutes([rootRouteConfig]);
|
|
2394
|
-
return routes[0];
|
|
2395
|
-
},
|
|
2396
|
-
parseLocation: (location, previousLocation) => {
|
|
2397
|
-
var _location$hash$split$;
|
|
2398
|
-
|
|
2399
|
-
const parsedSearch = router.options.parseSearch(location.search);
|
|
2400
|
-
return {
|
|
2401
|
-
pathname: location.pathname,
|
|
2402
|
-
searchStr: location.search,
|
|
2403
|
-
search: replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.search, parsedSearch),
|
|
2404
|
-
hash: (_location$hash$split$ = location.hash.split('#').reverse()[0]) != null ? _location$hash$split$ : '',
|
|
2405
|
-
href: "" + location.pathname + location.search + location.hash,
|
|
2406
|
-
state: location.state,
|
|
2407
|
-
key: location.key
|
|
2408
|
-
};
|
|
2409
|
-
},
|
|
2410
|
-
navigate: location => {
|
|
2411
|
-
const next = router.buildNext(location);
|
|
2412
|
-
return router.__.commitLocation(next, location.replace);
|
|
2413
|
-
},
|
|
2414
|
-
buildLocation: function buildLocation(dest) {
|
|
2415
|
-
var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
|
|
2416
|
-
|
|
2417
|
-
if (dest === void 0) {
|
|
2418
|
-
dest = {};
|
|
2419
|
-
}
|
|
2420
|
-
|
|
2421
|
-
// const resolvedFrom: Location = {
|
|
2422
|
-
// ...router.location,
|
|
2423
|
-
const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
|
|
2424
|
-
|
|
2425
|
-
let pathname = resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
|
|
2426
|
-
|
|
2427
|
-
const fromMatches = router.matchRoutes(router.location.pathname, {
|
|
2428
|
-
strictParseParams: true
|
|
2429
|
-
});
|
|
2430
|
-
const toMatches = router.matchRoutes(pathname);
|
|
2431
|
-
|
|
2432
|
-
const prevParams = _extends({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
|
|
2433
|
-
|
|
2434
|
-
let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
|
|
2435
|
-
|
|
2436
|
-
if (nextParams) {
|
|
2437
|
-
toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
|
|
2438
|
-
Object.assign({}, nextParams, fn(nextParams));
|
|
2439
|
-
});
|
|
2440
|
-
}
|
|
2441
|
-
|
|
2442
|
-
pathname = interpolatePath(pathname, nextParams != null ? nextParams : {}); // Pre filters first
|
|
2443
|
-
|
|
2444
|
-
const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.location.search) : router.location.search; // Then the link/navigate function
|
|
2445
|
-
|
|
2446
|
-
const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
|
|
2447
|
-
: dest.search ? (_functionalUpdate = functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
|
|
2448
|
-
: (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
|
|
2449
|
-
: {}; // Then post filters
|
|
2450
|
-
|
|
2451
|
-
const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
|
|
2452
|
-
const search = replaceEqualDeep(router.location.search, postFilteredSearch);
|
|
2453
|
-
const searchStr = router.options.stringifySearch(search);
|
|
2454
|
-
let hash = dest.hash === true ? router.location.hash : functionalUpdate(dest.hash, router.location.hash);
|
|
2455
|
-
hash = hash ? "#" + hash : '';
|
|
2456
|
-
return {
|
|
2457
|
-
pathname,
|
|
2458
|
-
search,
|
|
2459
|
-
searchStr,
|
|
2460
|
-
state: router.location.state,
|
|
2461
|
-
hash,
|
|
2462
|
-
href: "" + pathname + searchStr + hash,
|
|
2463
|
-
key: dest.key
|
|
2464
|
-
};
|
|
2465
|
-
},
|
|
2466
|
-
commitLocation: (next, replace) => {
|
|
2467
|
-
const id = '' + Date.now() + Math.random();
|
|
2468
|
-
if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
|
|
2469
|
-
let nextAction = 'replace';
|
|
2470
|
-
|
|
2471
|
-
if (!replace) {
|
|
2472
|
-
nextAction = 'push';
|
|
2473
|
-
}
|
|
2474
|
-
|
|
2475
|
-
const isSameUrl = router.__.parseLocation(history.location).href === next.href;
|
|
2476
|
-
|
|
2477
|
-
if (isSameUrl && !next.key) {
|
|
2478
|
-
nextAction = 'replace';
|
|
2479
|
-
}
|
|
2480
|
-
|
|
2481
|
-
if (nextAction === 'replace') {
|
|
2482
|
-
history.replace({
|
|
2483
|
-
pathname: next.pathname,
|
|
2484
|
-
hash: next.hash,
|
|
2485
|
-
search: next.searchStr
|
|
2486
|
-
}, _extends({
|
|
2487
|
-
id
|
|
2488
|
-
}, next.state));
|
|
2489
|
-
} else {
|
|
2490
|
-
history.push({
|
|
2491
|
-
pathname: next.pathname,
|
|
2492
|
-
hash: next.hash,
|
|
2493
|
-
search: next.searchStr
|
|
2494
|
-
}, {
|
|
2495
|
-
id
|
|
2496
|
-
});
|
|
16
|
+
function _extends() {
|
|
17
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
18
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
19
|
+
var source = arguments[i];
|
|
20
|
+
for (var key in source) {
|
|
21
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
22
|
+
target[key] = source[key];
|
|
2497
23
|
}
|
|
2498
|
-
|
|
2499
|
-
router.navigationPromise = new Promise(resolve => {
|
|
2500
|
-
const previousNavigationResolve = router.resolveNavigation;
|
|
2501
|
-
|
|
2502
|
-
router.resolveNavigation = () => {
|
|
2503
|
-
previousNavigationResolve();
|
|
2504
|
-
resolve();
|
|
2505
|
-
};
|
|
2506
|
-
});
|
|
2507
|
-
return router.navigationPromise;
|
|
2508
24
|
}
|
|
2509
25
|
}
|
|
26
|
+
return target;
|
|
2510
27
|
};
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
router.options.createRouter == null ? void 0 : router.options.createRouter(router);
|
|
2514
|
-
return router;
|
|
2515
|
-
}
|
|
2516
|
-
|
|
2517
|
-
function isCtrlEvent(e) {
|
|
2518
|
-
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
28
|
+
return _extends.apply(this, arguments);
|
|
2519
29
|
}
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
30
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
31
|
+
if (source == null) return {};
|
|
32
|
+
var target = {};
|
|
33
|
+
var sourceKeys = Object.keys(source);
|
|
34
|
+
var key, i;
|
|
35
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
36
|
+
key = sourceKeys[i];
|
|
37
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
38
|
+
target[key] = source[key];
|
|
39
|
+
}
|
|
40
|
+
return target;
|
|
2529
41
|
}
|
|
2530
42
|
|
|
2531
43
|
const _excluded = ["type", "children", "target", "activeProps", "inactiveProps", "activeOptions", "disabled", "hash", "search", "params", "to", "preload", "preloadDelay", "preloadMaxAge", "replace", "style", "className", "onClick", "onFocus", "onMouseEnter", "onMouseLeave", "onTouchStart", "onTouchEnd"],
|
|
2532
|
-
|
|
2533
|
-
|
|
44
|
+
_excluded2 = ["pending", "caseSensitive", "children"],
|
|
45
|
+
_excluded3 = ["router"];
|
|
2534
46
|
function lazy(importer) {
|
|
2535
47
|
const lazyComp = /*#__PURE__*/React.lazy(importer);
|
|
2536
48
|
let promise;
|
|
2537
49
|
let resolvedComp;
|
|
2538
50
|
const forwardedComp = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
2539
51
|
const resolvedCompRef = React.useRef(resolvedComp || lazyComp);
|
|
2540
|
-
return /*#__PURE__*/React.createElement(resolvedCompRef.current, _extends
|
|
52
|
+
return /*#__PURE__*/React.createElement(resolvedCompRef.current, _extends({}, ref ? {
|
|
2541
53
|
ref
|
|
2542
54
|
} : {}, props));
|
|
2543
55
|
});
|
|
2544
56
|
const finalComp = forwardedComp;
|
|
2545
|
-
|
|
2546
57
|
finalComp.preload = () => {
|
|
2547
58
|
if (!promise) {
|
|
2548
59
|
promise = importer().then(module => {
|
|
@@ -2550,13 +61,12 @@ function lazy(importer) {
|
|
|
2550
61
|
return resolvedComp;
|
|
2551
62
|
});
|
|
2552
63
|
}
|
|
2553
|
-
|
|
2554
64
|
return promise;
|
|
2555
65
|
};
|
|
2556
|
-
|
|
2557
66
|
return finalComp;
|
|
2558
67
|
}
|
|
2559
68
|
//
|
|
69
|
+
|
|
2560
70
|
function Link(props) {
|
|
2561
71
|
const router = useRouter();
|
|
2562
72
|
return /*#__PURE__*/React.createElement(router.Link, props);
|
|
@@ -2566,11 +76,9 @@ const routerContext = /*#__PURE__*/React.createContext(null);
|
|
|
2566
76
|
function MatchesProvider(props) {
|
|
2567
77
|
return /*#__PURE__*/React.createElement(matchesContext.Provider, props);
|
|
2568
78
|
}
|
|
2569
|
-
|
|
2570
79
|
const useRouterSubscription = router => {
|
|
2571
80
|
useSyncExternalStore(cb => router.subscribe(() => cb()), () => router.state, () => router.state);
|
|
2572
81
|
};
|
|
2573
|
-
|
|
2574
82
|
function createReactRouter(opts) {
|
|
2575
83
|
const makeRouteExt = (route, router) => {
|
|
2576
84
|
return {
|
|
@@ -2578,7 +86,6 @@ function createReactRouter(opts) {
|
|
|
2578
86
|
if (subRouteId === void 0) {
|
|
2579
87
|
subRouteId = '.';
|
|
2580
88
|
}
|
|
2581
|
-
|
|
2582
89
|
const resolvedRouteId = router.resolvePath(route.routeId, subRouteId);
|
|
2583
90
|
const resolvedRoute = router.getRoute(resolvedRouteId);
|
|
2584
91
|
useRouterSubscription(router);
|
|
@@ -2587,27 +94,25 @@ function createReactRouter(opts) {
|
|
|
2587
94
|
},
|
|
2588
95
|
linkProps: options => {
|
|
2589
96
|
var _functionalUpdate, _functionalUpdate2;
|
|
2590
|
-
|
|
2591
97
|
const {
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
98
|
+
// custom props
|
|
99
|
+
|
|
100
|
+
target,
|
|
101
|
+
activeProps = () => ({
|
|
102
|
+
className: 'active'
|
|
103
|
+
}),
|
|
104
|
+
inactiveProps = () => ({}),
|
|
105
|
+
disabled,
|
|
106
|
+
// element props
|
|
107
|
+
style,
|
|
108
|
+
className,
|
|
109
|
+
onClick,
|
|
110
|
+
onFocus,
|
|
111
|
+
onMouseEnter,
|
|
112
|
+
onMouseLeave
|
|
113
|
+
} = options,
|
|
114
|
+
rest = _objectWithoutPropertiesLoose(options, _excluded);
|
|
2609
115
|
const linkInfo = route.buildLink(options);
|
|
2610
|
-
|
|
2611
116
|
if (linkInfo.type === 'external') {
|
|
2612
117
|
const {
|
|
2613
118
|
href
|
|
@@ -2616,7 +121,6 @@ function createReactRouter(opts) {
|
|
|
2616
121
|
href
|
|
2617
122
|
};
|
|
2618
123
|
}
|
|
2619
|
-
|
|
2620
124
|
const {
|
|
2621
125
|
handleClick,
|
|
2622
126
|
handleFocus,
|
|
@@ -2625,33 +129,33 @@ function createReactRouter(opts) {
|
|
|
2625
129
|
isActive,
|
|
2626
130
|
next
|
|
2627
131
|
} = linkInfo;
|
|
2628
|
-
|
|
2629
132
|
const reactHandleClick = e => {
|
|
2630
|
-
if (React.startTransition)
|
|
133
|
+
if (React.startTransition)
|
|
134
|
+
// This is a hack for react < 18
|
|
2631
135
|
React.startTransition(() => {
|
|
2632
136
|
handleClick(e);
|
|
2633
137
|
});else handleClick(e);
|
|
2634
138
|
};
|
|
2635
|
-
|
|
2636
139
|
const composeHandlers = handlers => e => {
|
|
2637
140
|
e.persist();
|
|
2638
141
|
handlers.forEach(handler => {
|
|
2639
142
|
if (handler) handler(e);
|
|
2640
143
|
});
|
|
2641
|
-
};
|
|
2642
|
-
|
|
144
|
+
};
|
|
2643
145
|
|
|
2644
|
-
|
|
146
|
+
// Get the active props
|
|
147
|
+
const resolvedActiveProps = isActive ? (_functionalUpdate = functionalUpdate(activeProps, {})) != null ? _functionalUpdate : {} : {};
|
|
2645
148
|
|
|
149
|
+
// Get the inactive props
|
|
2646
150
|
const resolvedInactiveProps = isActive ? {} : (_functionalUpdate2 = functionalUpdate(inactiveProps, {})) != null ? _functionalUpdate2 : {};
|
|
2647
|
-
return _extends
|
|
151
|
+
return _extends({}, resolvedActiveProps, resolvedInactiveProps, rest, {
|
|
2648
152
|
href: disabled ? undefined : next.href,
|
|
2649
153
|
onClick: composeHandlers([reactHandleClick, onClick]),
|
|
2650
154
|
onFocus: composeHandlers([handleFocus, onFocus]),
|
|
2651
155
|
onMouseEnter: composeHandlers([handleEnter, onMouseEnter]),
|
|
2652
156
|
onMouseLeave: composeHandlers([handleLeave, onMouseLeave]),
|
|
2653
157
|
target,
|
|
2654
|
-
style: _extends
|
|
158
|
+
style: _extends({}, style, resolvedActiveProps.style, resolvedInactiveProps.style),
|
|
2655
159
|
className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined
|
|
2656
160
|
}, disabled ? {
|
|
2657
161
|
role: 'link',
|
|
@@ -2663,7 +167,7 @@ function createReactRouter(opts) {
|
|
|
2663
167
|
Link: /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
2664
168
|
const linkProps = route.linkProps(props);
|
|
2665
169
|
useRouterSubscription(router);
|
|
2666
|
-
return /*#__PURE__*/React.createElement("a", _extends
|
|
170
|
+
return /*#__PURE__*/React.createElement("a", _extends({
|
|
2667
171
|
ref: ref
|
|
2668
172
|
}, linkProps, {
|
|
2669
173
|
children: typeof props.children === 'function' ? props.children({
|
|
@@ -2673,26 +177,22 @@ function createReactRouter(opts) {
|
|
|
2673
177
|
}),
|
|
2674
178
|
MatchRoute: opts => {
|
|
2675
179
|
const {
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
180
|
+
pending,
|
|
181
|
+
caseSensitive
|
|
182
|
+
} = opts,
|
|
183
|
+
rest = _objectWithoutPropertiesLoose(opts, _excluded2);
|
|
2681
184
|
const params = route.matchRoute(rest, {
|
|
2682
185
|
pending,
|
|
2683
186
|
caseSensitive
|
|
2684
187
|
});
|
|
2685
|
-
|
|
2686
188
|
if (!params) {
|
|
2687
189
|
return null;
|
|
2688
190
|
}
|
|
2689
|
-
|
|
2690
191
|
return typeof opts.children === 'function' ? opts.children(params) : opts.children;
|
|
2691
192
|
}
|
|
2692
193
|
};
|
|
2693
194
|
};
|
|
2694
|
-
|
|
2695
|
-
const coreRouter = createRouter(_extends$2({}, opts, {
|
|
195
|
+
const coreRouter = createRouter(_extends({}, opts, {
|
|
2696
196
|
createRouter: router => {
|
|
2697
197
|
const routerExt = {
|
|
2698
198
|
useState: () => {
|
|
@@ -2700,18 +200,15 @@ function createReactRouter(opts) {
|
|
|
2700
200
|
return router.state;
|
|
2701
201
|
},
|
|
2702
202
|
useMatch: (routeId, opts) => {
|
|
2703
|
-
var
|
|
2704
|
-
|
|
203
|
+
var _opts$strict;
|
|
2705
204
|
useRouterSubscription(router);
|
|
2706
205
|
invariant(routeId !== rootRouteId, "\"" + rootRouteId + "\" cannot be used with useMatch! Did you mean to useRoute(\"" + rootRouteId + "\")?");
|
|
2707
|
-
const
|
|
206
|
+
const nearestMatch = useNearestMatch();
|
|
2708
207
|
const match = router.state.matches.find(d => d.routeId === routeId);
|
|
2709
|
-
|
|
2710
208
|
if ((_opts$strict = opts == null ? void 0 : opts.strict) != null ? _opts$strict : true) {
|
|
2711
209
|
invariant(match, "Could not find an active match for \"" + routeId + "\"!");
|
|
2712
|
-
invariant(
|
|
210
|
+
invariant(nearestMatch.routeId == (match == null ? void 0 : match.routeId), "useMatch(\"" + (match == null ? void 0 : match.routeId) + "\") is being called in a component that is meant to render the '" + nearestMatch.routeId + "' route. Did you mean to 'useMatch(\"" + (match == null ? void 0 : match.routeId) + "\", { strict: false })' or 'useRoute(\"" + (match == null ? void 0 : match.routeId) + "\")' instead?");
|
|
2713
211
|
}
|
|
2714
|
-
|
|
2715
212
|
return match;
|
|
2716
213
|
}
|
|
2717
214
|
};
|
|
@@ -2728,7 +225,8 @@ function createReactRouter(opts) {
|
|
|
2728
225
|
},
|
|
2729
226
|
loadComponent: async component => {
|
|
2730
227
|
if (component.preload && typeof document !== 'undefined') {
|
|
2731
|
-
component.preload();
|
|
228
|
+
component.preload();
|
|
229
|
+
// return await component.preload()
|
|
2732
230
|
}
|
|
2733
231
|
|
|
2734
232
|
return component;
|
|
@@ -2737,29 +235,22 @@ function createReactRouter(opts) {
|
|
|
2737
235
|
return coreRouter;
|
|
2738
236
|
}
|
|
2739
237
|
function RouterProvider(_ref2) {
|
|
2740
|
-
var _router$options$useCo;
|
|
2741
|
-
|
|
2742
238
|
let {
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
rest = _objectWithoutPropertiesLoose(_ref2, _excluded3);
|
|
2747
|
-
|
|
239
|
+
router
|
|
240
|
+
} = _ref2,
|
|
241
|
+
rest = _objectWithoutPropertiesLoose(_ref2, _excluded3);
|
|
2748
242
|
router.update(rest);
|
|
2749
|
-
const defaultRouterContext = React.useRef({});
|
|
2750
|
-
const userContext = (_router$options$useCo = router.options.useContext == null ? void 0 : router.options.useContext()) != null ? _router$options$useCo : defaultRouterContext.current;
|
|
2751
|
-
router.context = userContext;
|
|
2752
243
|
useRouterSubscription(router);
|
|
2753
244
|
React.useEffect(() => {
|
|
2754
245
|
return router.mount();
|
|
2755
246
|
}, [router]);
|
|
2756
|
-
return /*#__PURE__*/React.createElement(routerContext.Provider, {
|
|
247
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(routerContext.Provider, {
|
|
2757
248
|
value: {
|
|
2758
249
|
router: router
|
|
2759
250
|
}
|
|
2760
251
|
}, /*#__PURE__*/React.createElement(MatchesProvider, {
|
|
2761
|
-
value: router.state.matches
|
|
2762
|
-
},
|
|
252
|
+
value: [undefined, ...router.state.matches]
|
|
253
|
+
}, /*#__PURE__*/React.createElement(Outlet, null))));
|
|
2763
254
|
}
|
|
2764
255
|
function useRouter() {
|
|
2765
256
|
const value = React.useContext(routerContext);
|
|
@@ -2775,9 +266,7 @@ function useMatch(routeId, opts) {
|
|
|
2775
266
|
return router.useMatch(routeId, opts);
|
|
2776
267
|
}
|
|
2777
268
|
function useNearestMatch() {
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
const runtimeMatch = (_useMatches2 = useMatches()) == null ? void 0 : _useMatches2[0];
|
|
269
|
+
const runtimeMatch = useMatches()[0];
|
|
2781
270
|
invariant(runtimeMatch, "Could not find a nearest match!");
|
|
2782
271
|
return runtimeMatch;
|
|
2783
272
|
}
|
|
@@ -2798,16 +287,13 @@ function MatchRoute(props) {
|
|
|
2798
287
|
}
|
|
2799
288
|
function Outlet() {
|
|
2800
289
|
var _ref3, _match$__$pendingComp, _match$__$errorCompon;
|
|
2801
|
-
|
|
2802
290
|
const router = useRouter();
|
|
2803
291
|
const matches = useMatches().slice(1);
|
|
2804
292
|
const match = matches[0];
|
|
2805
293
|
const defaultPending = React.useCallback(() => null, []);
|
|
2806
|
-
|
|
2807
294
|
if (!match) {
|
|
2808
295
|
return null;
|
|
2809
296
|
}
|
|
2810
|
-
|
|
2811
297
|
const PendingComponent = (_ref3 = (_match$__$pendingComp = match.__.pendingComponent) != null ? _match$__$pendingComp : router.options.defaultPendingComponent) != null ? _ref3 : defaultPending;
|
|
2812
298
|
const errorComponent = (_match$__$errorCompon = match.__.errorComponent) != null ? _match$__$errorCompon : router.options.defaultErrorComponent;
|
|
2813
299
|
return /*#__PURE__*/React.createElement(MatchesProvider, {
|
|
@@ -2815,23 +301,20 @@ function Outlet() {
|
|
|
2815
301
|
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
2816
302
|
fallback: /*#__PURE__*/React.createElement(PendingComponent, null)
|
|
2817
303
|
}, /*#__PURE__*/React.createElement(CatchBoundary, {
|
|
304
|
+
key: match.routeId,
|
|
2818
305
|
errorComponent: errorComponent,
|
|
2819
|
-
|
|
306
|
+
match: match
|
|
2820
307
|
}, (() => {
|
|
2821
308
|
if (match.status === 'error') {
|
|
2822
309
|
throw match.error;
|
|
2823
310
|
}
|
|
2824
|
-
|
|
2825
311
|
if (match.status === 'success') {
|
|
2826
312
|
var _ref4, _ref5;
|
|
2827
|
-
|
|
2828
313
|
return /*#__PURE__*/React.createElement((_ref4 = (_ref5 = match.__.component) != null ? _ref5 : router.options.defaultComponent) != null ? _ref4 : Outlet);
|
|
2829
314
|
}
|
|
2830
|
-
|
|
2831
315
|
throw match.__.loadPromise;
|
|
2832
316
|
})())));
|
|
2833
317
|
}
|
|
2834
|
-
|
|
2835
318
|
class CatchBoundary extends React.Component {
|
|
2836
319
|
constructor() {
|
|
2837
320
|
super(...arguments);
|
|
@@ -2840,30 +323,27 @@ class CatchBoundary extends React.Component {
|
|
|
2840
323
|
info: undefined
|
|
2841
324
|
};
|
|
2842
325
|
}
|
|
2843
|
-
|
|
2844
326
|
componentDidCatch(error, info) {
|
|
327
|
+
console.error("Error in route match: " + this.props.match.matchId);
|
|
2845
328
|
console.error(error);
|
|
2846
329
|
this.setState({
|
|
2847
330
|
error,
|
|
2848
331
|
info
|
|
2849
332
|
});
|
|
2850
333
|
}
|
|
2851
|
-
|
|
2852
334
|
render() {
|
|
2853
|
-
return /*#__PURE__*/React.createElement(CatchBoundaryInner, _extends
|
|
335
|
+
return /*#__PURE__*/React.createElement(CatchBoundaryInner, _extends({}, this.props, {
|
|
2854
336
|
errorState: this.state,
|
|
2855
337
|
reset: () => this.setState({})
|
|
2856
338
|
}));
|
|
2857
339
|
}
|
|
340
|
+
}
|
|
2858
341
|
|
|
2859
|
-
|
|
342
|
+
// This is the messiest thing ever... I'm either seriously tired (likely) or
|
|
2860
343
|
// there has to be a better way to reset error boundaries when the
|
|
2861
344
|
// router's location key changes.
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
345
|
function CatchBoundaryInner(props) {
|
|
2865
346
|
var _props$errorComponent;
|
|
2866
|
-
|
|
2867
347
|
const [activeErrorState, setActiveErrorState] = React.useState(props.errorState);
|
|
2868
348
|
const router = useRouter();
|
|
2869
349
|
const errorComponent = (_props$errorComponent = props.errorComponent) != null ? _props$errorComponent : DefaultErrorBoundary;
|
|
@@ -2877,24 +357,19 @@ function CatchBoundaryInner(props) {
|
|
|
2877
357
|
}
|
|
2878
358
|
});
|
|
2879
359
|
}
|
|
2880
|
-
|
|
2881
360
|
return;
|
|
2882
361
|
}, [activeErrorState]);
|
|
2883
362
|
React.useEffect(() => {
|
|
2884
363
|
if (props.errorState.error) {
|
|
2885
364
|
setActiveErrorState(props.errorState);
|
|
2886
365
|
}
|
|
2887
|
-
|
|
2888
366
|
props.reset();
|
|
2889
367
|
}, [props.errorState.error]);
|
|
2890
|
-
|
|
2891
368
|
if (activeErrorState.error) {
|
|
2892
369
|
return /*#__PURE__*/React.createElement(errorComponent, activeErrorState);
|
|
2893
370
|
}
|
|
2894
|
-
|
|
2895
371
|
return props.children;
|
|
2896
372
|
}
|
|
2897
|
-
|
|
2898
373
|
function DefaultErrorBoundary(_ref6) {
|
|
2899
374
|
let {
|
|
2900
375
|
error
|
|
@@ -2947,5 +422,5 @@ function Prompt(_ref7) {
|
|
|
2947
422
|
return children != null ? children : null;
|
|
2948
423
|
}
|
|
2949
424
|
|
|
2950
|
-
export { DefaultErrorBoundary, Link, MatchRoute, MatchesProvider, Outlet, Prompt, RouterProvider,
|
|
425
|
+
export { DefaultErrorBoundary, Link, MatchRoute, MatchesProvider, Outlet, Prompt, RouterProvider, createReactRouter, lazy, linkProps, matchesContext, routerContext, useMatch, useMatches, useNearestMatch, usePrompt, useRoute, useRouter, useSearch };
|
|
2951
426
|
//# sourceMappingURL=index.js.map
|