@tanstack/router-core 0.0.1-beta.26 → 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 -2
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/cjs/{packages/router-core/src/index.js → index.js} +22 -6
- package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
- package/build/cjs/{packages/router-core/src/path.js → path.js} +4 -28
- package/build/cjs/path.js.map +1 -0
- package/build/cjs/{packages/router-core/src/qss.js → qss.js} +8 -13
- package/build/cjs/qss.js.map +1 -0
- package/build/cjs/{packages/router-core/src/route.js → route.js} +7 -16
- package/build/cjs/route.js.map +1 -0
- package/build/cjs/{packages/router-core/src/routeConfig.js → routeConfig.js} +10 -12
- package/build/cjs/routeConfig.js.map +1 -0
- package/build/cjs/{packages/router-core/src/routeMatch.js → routeMatch.js} +15 -35
- package/build/cjs/routeMatch.js.map +1 -0
- package/build/cjs/{packages/router-core/src/router.js → router.js} +103 -159
- package/build/cjs/router.js.map +1 -0
- package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +7 -10
- package/build/cjs/searchParams.js.map +1 -0
- package/build/cjs/{packages/router-core/src/utils.js → utils.js} +10 -24
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +150 -1112
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +59 -49
- package/build/stats-react.json +155 -155
- package/build/types/index.d.ts +34 -20
- package/build/umd/index.development.js +145 -290
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/route.ts +8 -5
- package/src/routeConfig.ts +6 -10
- package/src/routeMatch.ts +1 -1
- package/src/router.ts +114 -51
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
- package/build/cjs/node_modules/history/index.js +0 -815
- package/build/cjs/node_modules/history/index.js.map +0 -1
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
- package/build/cjs/packages/router-core/src/path.js.map +0 -1
- package/build/cjs/packages/router-core/src/qss.js.map +0 -1
- package/build/cjs/packages/router-core/src/route.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
- package/build/cjs/packages/router-core/src/router.js.map +0 -1
- package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
- package/build/cjs/packages/router-core/src/utils.js.map +0 -1
package/build/esm/index.js
CHANGED
|
@@ -8,829 +8,10 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
for (var key in source) {
|
|
17
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
18
|
-
target[key] = source[key];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return target;
|
|
24
|
-
};
|
|
25
|
-
return _extends$1.apply(this, arguments);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Actions represent the type of change to a location value.
|
|
30
|
-
*
|
|
31
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#action
|
|
32
|
-
*/
|
|
33
|
-
var Action;
|
|
34
|
-
|
|
35
|
-
(function (Action) {
|
|
36
|
-
/**
|
|
37
|
-
* A POP indicates a change to an arbitrary index in the history stack, such
|
|
38
|
-
* as a back or forward navigation. It does not describe the direction of the
|
|
39
|
-
* navigation, only that the current index changed.
|
|
40
|
-
*
|
|
41
|
-
* Note: This is the default action for newly created history objects.
|
|
42
|
-
*/
|
|
43
|
-
Action["Pop"] = "POP";
|
|
44
|
-
/**
|
|
45
|
-
* A PUSH indicates a new entry being added to the history stack, such as when
|
|
46
|
-
* a link is clicked and a new page loads. When this happens, all subsequent
|
|
47
|
-
* entries in the stack are lost.
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
Action["Push"] = "PUSH";
|
|
51
|
-
/**
|
|
52
|
-
* A REPLACE indicates the entry at the current index in the history stack
|
|
53
|
-
* being replaced by a new one.
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
Action["Replace"] = "REPLACE";
|
|
57
|
-
})(Action || (Action = {}));
|
|
58
|
-
|
|
59
|
-
var readOnly = process.env.NODE_ENV !== "production" ? function (obj) {
|
|
60
|
-
return Object.freeze(obj);
|
|
61
|
-
} : function (obj) {
|
|
62
|
-
return obj;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
function warning$1(cond, message) {
|
|
66
|
-
if (!cond) {
|
|
67
|
-
// eslint-disable-next-line no-console
|
|
68
|
-
if (typeof console !== 'undefined') console.warn(message);
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
// Welcome to debugging history!
|
|
72
|
-
//
|
|
73
|
-
// This error is thrown as a convenience so you can more easily
|
|
74
|
-
// find the source for a warning that appears in the console by
|
|
75
|
-
// enabling "pause on exceptions" in your JavaScript debugger.
|
|
76
|
-
throw new Error(message); // eslint-disable-next-line no-empty
|
|
77
|
-
} catch (e) {}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
var BeforeUnloadEventType = 'beforeunload';
|
|
82
|
-
var HashChangeEventType = 'hashchange';
|
|
83
|
-
var PopStateEventType = 'popstate';
|
|
84
|
-
/**
|
|
85
|
-
* Browser history stores the location in regular URLs. This is the standard for
|
|
86
|
-
* most web apps, but it requires some configuration on the server to ensure you
|
|
87
|
-
* serve the same app at multiple URLs.
|
|
88
|
-
*
|
|
89
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
function createBrowserHistory(options) {
|
|
93
|
-
if (options === void 0) {
|
|
94
|
-
options = {};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
var _options = options,
|
|
98
|
-
_options$window = _options.window,
|
|
99
|
-
window = _options$window === void 0 ? document.defaultView : _options$window;
|
|
100
|
-
var globalHistory = window.history;
|
|
101
|
-
|
|
102
|
-
function getIndexAndLocation() {
|
|
103
|
-
var _window$location = window.location,
|
|
104
|
-
pathname = _window$location.pathname,
|
|
105
|
-
search = _window$location.search,
|
|
106
|
-
hash = _window$location.hash;
|
|
107
|
-
var state = globalHistory.state || {};
|
|
108
|
-
return [state.idx, readOnly({
|
|
109
|
-
pathname: pathname,
|
|
110
|
-
search: search,
|
|
111
|
-
hash: hash,
|
|
112
|
-
state: state.usr || null,
|
|
113
|
-
key: state.key || 'default'
|
|
114
|
-
})];
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
var blockedPopTx = null;
|
|
118
|
-
|
|
119
|
-
function handlePop() {
|
|
120
|
-
if (blockedPopTx) {
|
|
121
|
-
blockers.call(blockedPopTx);
|
|
122
|
-
blockedPopTx = null;
|
|
123
|
-
} else {
|
|
124
|
-
var nextAction = Action.Pop;
|
|
125
|
-
|
|
126
|
-
var _getIndexAndLocation = getIndexAndLocation(),
|
|
127
|
-
nextIndex = _getIndexAndLocation[0],
|
|
128
|
-
nextLocation = _getIndexAndLocation[1];
|
|
129
|
-
|
|
130
|
-
if (blockers.length) {
|
|
131
|
-
if (nextIndex != null) {
|
|
132
|
-
var delta = index - nextIndex;
|
|
133
|
-
|
|
134
|
-
if (delta) {
|
|
135
|
-
// Revert the POP
|
|
136
|
-
blockedPopTx = {
|
|
137
|
-
action: nextAction,
|
|
138
|
-
location: nextLocation,
|
|
139
|
-
retry: function retry() {
|
|
140
|
-
go(delta * -1);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
go(delta);
|
|
144
|
-
}
|
|
145
|
-
} else {
|
|
146
|
-
// Trying to POP to a location with no index. We did not create
|
|
147
|
-
// this location, so we can't effectively block the navigation.
|
|
148
|
-
process.env.NODE_ENV !== "production" ? warning$1(false, // TODO: Write up a doc that explains our blocking strategy in
|
|
149
|
-
// detail and link to it here so people can understand better what
|
|
150
|
-
// is going on and how to avoid it.
|
|
151
|
-
"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;
|
|
152
|
-
}
|
|
153
|
-
} else {
|
|
154
|
-
applyTx(nextAction);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
window.addEventListener(PopStateEventType, handlePop);
|
|
160
|
-
var action = Action.Pop;
|
|
161
|
-
|
|
162
|
-
var _getIndexAndLocation2 = getIndexAndLocation(),
|
|
163
|
-
index = _getIndexAndLocation2[0],
|
|
164
|
-
location = _getIndexAndLocation2[1];
|
|
165
|
-
|
|
166
|
-
var listeners = createEvents();
|
|
167
|
-
var blockers = createEvents();
|
|
168
|
-
|
|
169
|
-
if (index == null) {
|
|
170
|
-
index = 0;
|
|
171
|
-
globalHistory.replaceState(_extends$1({}, globalHistory.state, {
|
|
172
|
-
idx: index
|
|
173
|
-
}), '');
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function createHref(to) {
|
|
177
|
-
return typeof to === 'string' ? to : createPath(to);
|
|
178
|
-
} // state defaults to `null` because `window.history.state` does
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
function getNextLocation(to, state) {
|
|
182
|
-
if (state === void 0) {
|
|
183
|
-
state = null;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return readOnly(_extends$1({
|
|
187
|
-
pathname: location.pathname,
|
|
188
|
-
hash: '',
|
|
189
|
-
search: ''
|
|
190
|
-
}, typeof to === 'string' ? parsePath(to) : to, {
|
|
191
|
-
state: state,
|
|
192
|
-
key: createKey()
|
|
193
|
-
}));
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function getHistoryStateAndUrl(nextLocation, index) {
|
|
197
|
-
return [{
|
|
198
|
-
usr: nextLocation.state,
|
|
199
|
-
key: nextLocation.key,
|
|
200
|
-
idx: index
|
|
201
|
-
}, createHref(nextLocation)];
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function allowTx(action, location, retry) {
|
|
205
|
-
return !blockers.length || (blockers.call({
|
|
206
|
-
action: action,
|
|
207
|
-
location: location,
|
|
208
|
-
retry: retry
|
|
209
|
-
}), false);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function applyTx(nextAction) {
|
|
213
|
-
action = nextAction;
|
|
214
|
-
|
|
215
|
-
var _getIndexAndLocation3 = getIndexAndLocation();
|
|
216
|
-
|
|
217
|
-
index = _getIndexAndLocation3[0];
|
|
218
|
-
location = _getIndexAndLocation3[1];
|
|
219
|
-
listeners.call({
|
|
220
|
-
action: action,
|
|
221
|
-
location: location
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function push(to, state) {
|
|
226
|
-
var nextAction = Action.Push;
|
|
227
|
-
var nextLocation = getNextLocation(to, state);
|
|
228
|
-
|
|
229
|
-
function retry() {
|
|
230
|
-
push(to, state);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
234
|
-
var _getHistoryStateAndUr = getHistoryStateAndUrl(nextLocation, index + 1),
|
|
235
|
-
historyState = _getHistoryStateAndUr[0],
|
|
236
|
-
url = _getHistoryStateAndUr[1]; // TODO: Support forced reloading
|
|
237
|
-
// try...catch because iOS limits us to 100 pushState calls :/
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
try {
|
|
241
|
-
globalHistory.pushState(historyState, '', url);
|
|
242
|
-
} catch (error) {
|
|
243
|
-
// They are going to lose state here, but there is no real
|
|
244
|
-
// way to warn them about it since the page will refresh...
|
|
245
|
-
window.location.assign(url);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
applyTx(nextAction);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function replace(to, state) {
|
|
253
|
-
var nextAction = Action.Replace;
|
|
254
|
-
var nextLocation = getNextLocation(to, state);
|
|
255
|
-
|
|
256
|
-
function retry() {
|
|
257
|
-
replace(to, state);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
261
|
-
var _getHistoryStateAndUr2 = getHistoryStateAndUrl(nextLocation, index),
|
|
262
|
-
historyState = _getHistoryStateAndUr2[0],
|
|
263
|
-
url = _getHistoryStateAndUr2[1]; // TODO: Support forced reloading
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
globalHistory.replaceState(historyState, '', url);
|
|
267
|
-
applyTx(nextAction);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
function go(delta) {
|
|
272
|
-
globalHistory.go(delta);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
var history = {
|
|
276
|
-
get action() {
|
|
277
|
-
return action;
|
|
278
|
-
},
|
|
279
|
-
|
|
280
|
-
get location() {
|
|
281
|
-
return location;
|
|
282
|
-
},
|
|
283
|
-
|
|
284
|
-
createHref: createHref,
|
|
285
|
-
push: push,
|
|
286
|
-
replace: replace,
|
|
287
|
-
go: go,
|
|
288
|
-
back: function back() {
|
|
289
|
-
go(-1);
|
|
290
|
-
},
|
|
291
|
-
forward: function forward() {
|
|
292
|
-
go(1);
|
|
293
|
-
},
|
|
294
|
-
listen: function listen(listener) {
|
|
295
|
-
return listeners.push(listener);
|
|
296
|
-
},
|
|
297
|
-
block: function block(blocker) {
|
|
298
|
-
var unblock = blockers.push(blocker);
|
|
299
|
-
|
|
300
|
-
if (blockers.length === 1) {
|
|
301
|
-
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
return function () {
|
|
305
|
-
unblock(); // Remove the beforeunload listener so the document may
|
|
306
|
-
// still be salvageable in the pagehide event.
|
|
307
|
-
// See https://html.spec.whatwg.org/#unloading-documents
|
|
308
|
-
|
|
309
|
-
if (!blockers.length) {
|
|
310
|
-
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
return history;
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Hash history stores the location in window.location.hash. This makes it ideal
|
|
319
|
-
* for situations where you don't want to send the location to the server for
|
|
320
|
-
* some reason, either because you do cannot configure it or the URL space is
|
|
321
|
-
* reserved for something else.
|
|
322
|
-
*
|
|
323
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
|
|
324
|
-
*/
|
|
325
|
-
|
|
326
|
-
function createHashHistory(options) {
|
|
327
|
-
if (options === void 0) {
|
|
328
|
-
options = {};
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
var _options2 = options,
|
|
332
|
-
_options2$window = _options2.window,
|
|
333
|
-
window = _options2$window === void 0 ? document.defaultView : _options2$window;
|
|
334
|
-
var globalHistory = window.history;
|
|
335
|
-
|
|
336
|
-
function getIndexAndLocation() {
|
|
337
|
-
var _parsePath = parsePath(window.location.hash.substr(1)),
|
|
338
|
-
_parsePath$pathname = _parsePath.pathname,
|
|
339
|
-
pathname = _parsePath$pathname === void 0 ? '/' : _parsePath$pathname,
|
|
340
|
-
_parsePath$search = _parsePath.search,
|
|
341
|
-
search = _parsePath$search === void 0 ? '' : _parsePath$search,
|
|
342
|
-
_parsePath$hash = _parsePath.hash,
|
|
343
|
-
hash = _parsePath$hash === void 0 ? '' : _parsePath$hash;
|
|
344
|
-
|
|
345
|
-
var state = globalHistory.state || {};
|
|
346
|
-
return [state.idx, readOnly({
|
|
347
|
-
pathname: pathname,
|
|
348
|
-
search: search,
|
|
349
|
-
hash: hash,
|
|
350
|
-
state: state.usr || null,
|
|
351
|
-
key: state.key || 'default'
|
|
352
|
-
})];
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
var blockedPopTx = null;
|
|
356
|
-
|
|
357
|
-
function handlePop() {
|
|
358
|
-
if (blockedPopTx) {
|
|
359
|
-
blockers.call(blockedPopTx);
|
|
360
|
-
blockedPopTx = null;
|
|
361
|
-
} else {
|
|
362
|
-
var nextAction = Action.Pop;
|
|
363
|
-
|
|
364
|
-
var _getIndexAndLocation4 = getIndexAndLocation(),
|
|
365
|
-
nextIndex = _getIndexAndLocation4[0],
|
|
366
|
-
nextLocation = _getIndexAndLocation4[1];
|
|
367
|
-
|
|
368
|
-
if (blockers.length) {
|
|
369
|
-
if (nextIndex != null) {
|
|
370
|
-
var delta = index - nextIndex;
|
|
371
|
-
|
|
372
|
-
if (delta) {
|
|
373
|
-
// Revert the POP
|
|
374
|
-
blockedPopTx = {
|
|
375
|
-
action: nextAction,
|
|
376
|
-
location: nextLocation,
|
|
377
|
-
retry: function retry() {
|
|
378
|
-
go(delta * -1);
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
go(delta);
|
|
382
|
-
}
|
|
383
|
-
} else {
|
|
384
|
-
// Trying to POP to a location with no index. We did not create
|
|
385
|
-
// this location, so we can't effectively block the navigation.
|
|
386
|
-
process.env.NODE_ENV !== "production" ? warning$1(false, // TODO: Write up a doc that explains our blocking strategy in
|
|
387
|
-
// detail and link to it here so people can understand better
|
|
388
|
-
// what is going on and how to avoid it.
|
|
389
|
-
"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;
|
|
390
|
-
}
|
|
391
|
-
} else {
|
|
392
|
-
applyTx(nextAction);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
window.addEventListener(PopStateEventType, handlePop); // popstate does not fire on hashchange in IE 11 and old (trident) Edge
|
|
398
|
-
// https://developer.mozilla.org/de/docs/Web/API/Window/popstate_event
|
|
399
|
-
|
|
400
|
-
window.addEventListener(HashChangeEventType, function () {
|
|
401
|
-
var _getIndexAndLocation5 = getIndexAndLocation(),
|
|
402
|
-
nextLocation = _getIndexAndLocation5[1]; // Ignore extraneous hashchange events.
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
if (createPath(nextLocation) !== createPath(location)) {
|
|
406
|
-
handlePop();
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
var action = Action.Pop;
|
|
410
|
-
|
|
411
|
-
var _getIndexAndLocation6 = getIndexAndLocation(),
|
|
412
|
-
index = _getIndexAndLocation6[0],
|
|
413
|
-
location = _getIndexAndLocation6[1];
|
|
414
|
-
|
|
415
|
-
var listeners = createEvents();
|
|
416
|
-
var blockers = createEvents();
|
|
417
|
-
|
|
418
|
-
if (index == null) {
|
|
419
|
-
index = 0;
|
|
420
|
-
globalHistory.replaceState(_extends$1({}, globalHistory.state, {
|
|
421
|
-
idx: index
|
|
422
|
-
}), '');
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
function getBaseHref() {
|
|
426
|
-
var base = document.querySelector('base');
|
|
427
|
-
var href = '';
|
|
428
|
-
|
|
429
|
-
if (base && base.getAttribute('href')) {
|
|
430
|
-
var url = window.location.href;
|
|
431
|
-
var hashIndex = url.indexOf('#');
|
|
432
|
-
href = hashIndex === -1 ? url : url.slice(0, hashIndex);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
return href;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
function createHref(to) {
|
|
439
|
-
return getBaseHref() + '#' + (typeof to === 'string' ? to : createPath(to));
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
function getNextLocation(to, state) {
|
|
443
|
-
if (state === void 0) {
|
|
444
|
-
state = null;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
return readOnly(_extends$1({
|
|
448
|
-
pathname: location.pathname,
|
|
449
|
-
hash: '',
|
|
450
|
-
search: ''
|
|
451
|
-
}, typeof to === 'string' ? parsePath(to) : to, {
|
|
452
|
-
state: state,
|
|
453
|
-
key: createKey()
|
|
454
|
-
}));
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
function getHistoryStateAndUrl(nextLocation, index) {
|
|
458
|
-
return [{
|
|
459
|
-
usr: nextLocation.state,
|
|
460
|
-
key: nextLocation.key,
|
|
461
|
-
idx: index
|
|
462
|
-
}, createHref(nextLocation)];
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
function allowTx(action, location, retry) {
|
|
466
|
-
return !blockers.length || (blockers.call({
|
|
467
|
-
action: action,
|
|
468
|
-
location: location,
|
|
469
|
-
retry: retry
|
|
470
|
-
}), false);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
function applyTx(nextAction) {
|
|
474
|
-
action = nextAction;
|
|
475
|
-
|
|
476
|
-
var _getIndexAndLocation7 = getIndexAndLocation();
|
|
477
|
-
|
|
478
|
-
index = _getIndexAndLocation7[0];
|
|
479
|
-
location = _getIndexAndLocation7[1];
|
|
480
|
-
listeners.call({
|
|
481
|
-
action: action,
|
|
482
|
-
location: location
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
function push(to, state) {
|
|
487
|
-
var nextAction = Action.Push;
|
|
488
|
-
var nextLocation = getNextLocation(to, state);
|
|
489
|
-
|
|
490
|
-
function retry() {
|
|
491
|
-
push(to, state);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
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;
|
|
495
|
-
|
|
496
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
497
|
-
var _getHistoryStateAndUr3 = getHistoryStateAndUrl(nextLocation, index + 1),
|
|
498
|
-
historyState = _getHistoryStateAndUr3[0],
|
|
499
|
-
url = _getHistoryStateAndUr3[1]; // TODO: Support forced reloading
|
|
500
|
-
// try...catch because iOS limits us to 100 pushState calls :/
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
try {
|
|
504
|
-
globalHistory.pushState(historyState, '', url);
|
|
505
|
-
} catch (error) {
|
|
506
|
-
// They are going to lose state here, but there is no real
|
|
507
|
-
// way to warn them about it since the page will refresh...
|
|
508
|
-
window.location.assign(url);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
applyTx(nextAction);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
function replace(to, state) {
|
|
516
|
-
var nextAction = Action.Replace;
|
|
517
|
-
var nextLocation = getNextLocation(to, state);
|
|
518
|
-
|
|
519
|
-
function retry() {
|
|
520
|
-
replace(to, state);
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
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;
|
|
524
|
-
|
|
525
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
526
|
-
var _getHistoryStateAndUr4 = getHistoryStateAndUrl(nextLocation, index),
|
|
527
|
-
historyState = _getHistoryStateAndUr4[0],
|
|
528
|
-
url = _getHistoryStateAndUr4[1]; // TODO: Support forced reloading
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
globalHistory.replaceState(historyState, '', url);
|
|
532
|
-
applyTx(nextAction);
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
function go(delta) {
|
|
537
|
-
globalHistory.go(delta);
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
var history = {
|
|
541
|
-
get action() {
|
|
542
|
-
return action;
|
|
543
|
-
},
|
|
544
|
-
|
|
545
|
-
get location() {
|
|
546
|
-
return location;
|
|
547
|
-
},
|
|
548
|
-
|
|
549
|
-
createHref: createHref,
|
|
550
|
-
push: push,
|
|
551
|
-
replace: replace,
|
|
552
|
-
go: go,
|
|
553
|
-
back: function back() {
|
|
554
|
-
go(-1);
|
|
555
|
-
},
|
|
556
|
-
forward: function forward() {
|
|
557
|
-
go(1);
|
|
558
|
-
},
|
|
559
|
-
listen: function listen(listener) {
|
|
560
|
-
return listeners.push(listener);
|
|
561
|
-
},
|
|
562
|
-
block: function block(blocker) {
|
|
563
|
-
var unblock = blockers.push(blocker);
|
|
564
|
-
|
|
565
|
-
if (blockers.length === 1) {
|
|
566
|
-
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
return function () {
|
|
570
|
-
unblock(); // Remove the beforeunload listener so the document may
|
|
571
|
-
// still be salvageable in the pagehide event.
|
|
572
|
-
// See https://html.spec.whatwg.org/#unloading-documents
|
|
573
|
-
|
|
574
|
-
if (!blockers.length) {
|
|
575
|
-
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
576
|
-
}
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
|
-
return history;
|
|
581
|
-
}
|
|
582
|
-
/**
|
|
583
|
-
* Memory history stores the current location in memory. It is designed for use
|
|
584
|
-
* in stateful non-browser environments like tests and React Native.
|
|
585
|
-
*
|
|
586
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#creatememoryhistory
|
|
587
|
-
*/
|
|
588
|
-
|
|
589
|
-
function createMemoryHistory(options) {
|
|
590
|
-
if (options === void 0) {
|
|
591
|
-
options = {};
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
var _options3 = options,
|
|
595
|
-
_options3$initialEntr = _options3.initialEntries,
|
|
596
|
-
initialEntries = _options3$initialEntr === void 0 ? ['/'] : _options3$initialEntr,
|
|
597
|
-
initialIndex = _options3.initialIndex;
|
|
598
|
-
var entries = initialEntries.map(function (entry) {
|
|
599
|
-
var location = readOnly(_extends$1({
|
|
600
|
-
pathname: '/',
|
|
601
|
-
search: '',
|
|
602
|
-
hash: '',
|
|
603
|
-
state: null,
|
|
604
|
-
key: createKey()
|
|
605
|
-
}, typeof entry === 'string' ? parsePath(entry) : entry));
|
|
606
|
-
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;
|
|
607
|
-
return location;
|
|
608
|
-
});
|
|
609
|
-
var index = clamp(initialIndex == null ? entries.length - 1 : initialIndex, 0, entries.length - 1);
|
|
610
|
-
var action = Action.Pop;
|
|
611
|
-
var location = entries[index];
|
|
612
|
-
var listeners = createEvents();
|
|
613
|
-
var blockers = createEvents();
|
|
614
|
-
|
|
615
|
-
function createHref(to) {
|
|
616
|
-
return typeof to === 'string' ? to : createPath(to);
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
function getNextLocation(to, state) {
|
|
620
|
-
if (state === void 0) {
|
|
621
|
-
state = null;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
return readOnly(_extends$1({
|
|
625
|
-
pathname: location.pathname,
|
|
626
|
-
search: '',
|
|
627
|
-
hash: ''
|
|
628
|
-
}, typeof to === 'string' ? parsePath(to) : to, {
|
|
629
|
-
state: state,
|
|
630
|
-
key: createKey()
|
|
631
|
-
}));
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
function allowTx(action, location, retry) {
|
|
635
|
-
return !blockers.length || (blockers.call({
|
|
636
|
-
action: action,
|
|
637
|
-
location: location,
|
|
638
|
-
retry: retry
|
|
639
|
-
}), false);
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
function applyTx(nextAction, nextLocation) {
|
|
643
|
-
action = nextAction;
|
|
644
|
-
location = nextLocation;
|
|
645
|
-
listeners.call({
|
|
646
|
-
action: action,
|
|
647
|
-
location: location
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
function push(to, state) {
|
|
652
|
-
var nextAction = Action.Push;
|
|
653
|
-
var nextLocation = getNextLocation(to, state);
|
|
654
|
-
|
|
655
|
-
function retry() {
|
|
656
|
-
push(to, state);
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
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;
|
|
660
|
-
|
|
661
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
662
|
-
index += 1;
|
|
663
|
-
entries.splice(index, entries.length, nextLocation);
|
|
664
|
-
applyTx(nextAction, nextLocation);
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
function replace(to, state) {
|
|
669
|
-
var nextAction = Action.Replace;
|
|
670
|
-
var nextLocation = getNextLocation(to, state);
|
|
671
|
-
|
|
672
|
-
function retry() {
|
|
673
|
-
replace(to, state);
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
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;
|
|
677
|
-
|
|
678
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
679
|
-
entries[index] = nextLocation;
|
|
680
|
-
applyTx(nextAction, nextLocation);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
function go(delta) {
|
|
685
|
-
var nextIndex = clamp(index + delta, 0, entries.length - 1);
|
|
686
|
-
var nextAction = Action.Pop;
|
|
687
|
-
var nextLocation = entries[nextIndex];
|
|
688
|
-
|
|
689
|
-
function retry() {
|
|
690
|
-
go(delta);
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
694
|
-
index = nextIndex;
|
|
695
|
-
applyTx(nextAction, nextLocation);
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
var history = {
|
|
700
|
-
get index() {
|
|
701
|
-
return index;
|
|
702
|
-
},
|
|
703
|
-
|
|
704
|
-
get action() {
|
|
705
|
-
return action;
|
|
706
|
-
},
|
|
707
|
-
|
|
708
|
-
get location() {
|
|
709
|
-
return location;
|
|
710
|
-
},
|
|
711
|
-
|
|
712
|
-
createHref: createHref,
|
|
713
|
-
push: push,
|
|
714
|
-
replace: replace,
|
|
715
|
-
go: go,
|
|
716
|
-
back: function back() {
|
|
717
|
-
go(-1);
|
|
718
|
-
},
|
|
719
|
-
forward: function forward() {
|
|
720
|
-
go(1);
|
|
721
|
-
},
|
|
722
|
-
listen: function listen(listener) {
|
|
723
|
-
return listeners.push(listener);
|
|
724
|
-
},
|
|
725
|
-
block: function block(blocker) {
|
|
726
|
-
return blockers.push(blocker);
|
|
727
|
-
}
|
|
728
|
-
};
|
|
729
|
-
return history;
|
|
730
|
-
} ////////////////////////////////////////////////////////////////////////////////
|
|
731
|
-
// UTILS
|
|
732
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
733
|
-
|
|
734
|
-
function clamp(n, lowerBound, upperBound) {
|
|
735
|
-
return Math.min(Math.max(n, lowerBound), upperBound);
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
function promptBeforeUnload(event) {
|
|
739
|
-
// Cancel the event.
|
|
740
|
-
event.preventDefault(); // Chrome (and legacy IE) requires returnValue to be set.
|
|
741
|
-
|
|
742
|
-
event.returnValue = '';
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
function createEvents() {
|
|
746
|
-
var handlers = [];
|
|
747
|
-
return {
|
|
748
|
-
get length() {
|
|
749
|
-
return handlers.length;
|
|
750
|
-
},
|
|
751
|
-
|
|
752
|
-
push: function push(fn) {
|
|
753
|
-
handlers.push(fn);
|
|
754
|
-
return function () {
|
|
755
|
-
handlers = handlers.filter(function (handler) {
|
|
756
|
-
return handler !== fn;
|
|
757
|
-
});
|
|
758
|
-
};
|
|
759
|
-
},
|
|
760
|
-
call: function call(arg) {
|
|
761
|
-
handlers.forEach(function (fn) {
|
|
762
|
-
return fn && fn(arg);
|
|
763
|
-
});
|
|
764
|
-
}
|
|
765
|
-
};
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
function createKey() {
|
|
769
|
-
return Math.random().toString(36).substr(2, 8);
|
|
770
|
-
}
|
|
771
|
-
/**
|
|
772
|
-
* Creates a string URL path from the given pathname, search, and hash components.
|
|
773
|
-
*
|
|
774
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createpath
|
|
775
|
-
*/
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
function createPath(_ref) {
|
|
779
|
-
var _ref$pathname = _ref.pathname,
|
|
780
|
-
pathname = _ref$pathname === void 0 ? '/' : _ref$pathname,
|
|
781
|
-
_ref$search = _ref.search,
|
|
782
|
-
search = _ref$search === void 0 ? '' : _ref$search,
|
|
783
|
-
_ref$hash = _ref.hash,
|
|
784
|
-
hash = _ref$hash === void 0 ? '' : _ref$hash;
|
|
785
|
-
if (search && search !== '?') pathname += search.charAt(0) === '?' ? search : '?' + search;
|
|
786
|
-
if (hash && hash !== '#') pathname += hash.charAt(0) === '#' ? hash : '#' + hash;
|
|
787
|
-
return pathname;
|
|
788
|
-
}
|
|
789
|
-
/**
|
|
790
|
-
* Parses a string URL path into its separate pathname, search, and hash components.
|
|
791
|
-
*
|
|
792
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#parsepath
|
|
793
|
-
*/
|
|
794
|
-
|
|
795
|
-
function parsePath(path) {
|
|
796
|
-
var parsedPath = {};
|
|
797
|
-
|
|
798
|
-
if (path) {
|
|
799
|
-
var hashIndex = path.indexOf('#');
|
|
800
|
-
|
|
801
|
-
if (hashIndex >= 0) {
|
|
802
|
-
parsedPath.hash = path.substr(hashIndex);
|
|
803
|
-
path = path.substr(0, hashIndex);
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
var searchIndex = path.indexOf('?');
|
|
807
|
-
|
|
808
|
-
if (searchIndex >= 0) {
|
|
809
|
-
parsedPath.search = path.substr(searchIndex);
|
|
810
|
-
path = path.substr(0, searchIndex);
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
if (path) {
|
|
814
|
-
parsedPath.pathname = path;
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
return parsedPath;
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
var isProduction = process.env.NODE_ENV === 'production';
|
|
822
|
-
var prefix = 'Invariant failed';
|
|
823
|
-
function invariant(condition, message) {
|
|
824
|
-
if (condition) {
|
|
825
|
-
return;
|
|
826
|
-
}
|
|
827
|
-
if (isProduction) {
|
|
828
|
-
throw new Error(prefix);
|
|
829
|
-
}
|
|
830
|
-
var provided = typeof message === 'function' ? message() : message;
|
|
831
|
-
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
|
832
|
-
throw new Error(value);
|
|
833
|
-
}
|
|
11
|
+
import { createMemoryHistory, createBrowserHistory } from 'history';
|
|
12
|
+
export { createBrowserHistory, createHashHistory, createMemoryHistory } from 'history';
|
|
13
|
+
import invariant from 'tiny-invariant';
|
|
14
|
+
export { default as invariant } from 'tiny-invariant';
|
|
834
15
|
|
|
835
16
|
/**
|
|
836
17
|
* This function returns `a` if `b` is deeply equal.
|
|
@@ -841,87 +22,73 @@ function replaceEqualDeep(prev, next) {
|
|
|
841
22
|
if (prev === next) {
|
|
842
23
|
return prev;
|
|
843
24
|
}
|
|
844
|
-
|
|
845
25
|
const array = Array.isArray(prev) && Array.isArray(next);
|
|
846
|
-
|
|
847
26
|
if (array || isPlainObject(prev) && isPlainObject(next)) {
|
|
848
27
|
const aSize = array ? prev.length : Object.keys(prev).length;
|
|
849
28
|
const bItems = array ? next : Object.keys(next);
|
|
850
29
|
const bSize = bItems.length;
|
|
851
30
|
const copy = array ? [] : {};
|
|
852
31
|
let equalItems = 0;
|
|
853
|
-
|
|
854
32
|
for (let i = 0; i < bSize; i++) {
|
|
855
33
|
const key = array ? i : bItems[i];
|
|
856
34
|
copy[key] = replaceEqualDeep(prev[key], next[key]);
|
|
857
|
-
|
|
858
35
|
if (copy[key] === prev[key]) {
|
|
859
36
|
equalItems++;
|
|
860
37
|
}
|
|
861
38
|
}
|
|
862
|
-
|
|
863
39
|
return aSize === bSize && equalItems === aSize ? prev : copy;
|
|
864
40
|
}
|
|
865
|
-
|
|
866
41
|
return next;
|
|
867
|
-
}
|
|
42
|
+
}
|
|
868
43
|
|
|
44
|
+
// Copied from: https://github.com/jonschlinkert/is-plain-object
|
|
869
45
|
function isPlainObject(o) {
|
|
870
46
|
if (!hasObjectPrototype(o)) {
|
|
871
47
|
return false;
|
|
872
|
-
}
|
|
873
|
-
|
|
48
|
+
}
|
|
874
49
|
|
|
50
|
+
// If has modified constructor
|
|
875
51
|
const ctor = o.constructor;
|
|
876
|
-
|
|
877
52
|
if (typeof ctor === 'undefined') {
|
|
878
53
|
return true;
|
|
879
|
-
}
|
|
880
|
-
|
|
54
|
+
}
|
|
881
55
|
|
|
56
|
+
// If has modified prototype
|
|
882
57
|
const prot = ctor.prototype;
|
|
883
|
-
|
|
884
58
|
if (!hasObjectPrototype(prot)) {
|
|
885
59
|
return false;
|
|
886
|
-
}
|
|
887
|
-
|
|
60
|
+
}
|
|
888
61
|
|
|
62
|
+
// If constructor does not have an Object-specific method
|
|
889
63
|
if (!prot.hasOwnProperty('isPrototypeOf')) {
|
|
890
64
|
return false;
|
|
891
|
-
}
|
|
892
|
-
|
|
65
|
+
}
|
|
893
66
|
|
|
67
|
+
// Most likely a plain Object
|
|
894
68
|
return true;
|
|
895
69
|
}
|
|
896
|
-
|
|
897
70
|
function hasObjectPrototype(o) {
|
|
898
71
|
return Object.prototype.toString.call(o) === '[object Object]';
|
|
899
72
|
}
|
|
900
|
-
|
|
901
73
|
function last(arr) {
|
|
902
74
|
return arr[arr.length - 1];
|
|
903
75
|
}
|
|
904
76
|
function warning(cond, message) {
|
|
905
77
|
if (cond) {
|
|
906
78
|
if (typeof console !== 'undefined') console.warn(message);
|
|
907
|
-
|
|
908
79
|
try {
|
|
909
80
|
throw new Error(message);
|
|
910
81
|
} catch (_unused) {}
|
|
911
82
|
}
|
|
912
|
-
|
|
913
83
|
return true;
|
|
914
84
|
}
|
|
915
|
-
|
|
916
85
|
function isFunction(d) {
|
|
917
86
|
return typeof d === 'function';
|
|
918
87
|
}
|
|
919
|
-
|
|
920
88
|
function functionalUpdate(updater, previous) {
|
|
921
89
|
if (isFunction(updater)) {
|
|
922
90
|
return updater(previous);
|
|
923
91
|
}
|
|
924
|
-
|
|
925
92
|
return updater;
|
|
926
93
|
}
|
|
927
94
|
function pick(parent, keys) {
|
|
@@ -963,12 +130,10 @@ function resolvePath(basepath, base, to) {
|
|
|
963
130
|
} else ;
|
|
964
131
|
} else if (toSegment.value === '..') {
|
|
965
132
|
var _last;
|
|
966
|
-
|
|
967
133
|
// Extra trailing slash? pop it off
|
|
968
134
|
if (baseSegments.length > 1 && ((_last = last(baseSegments)) == null ? void 0 : _last.value) === '/') {
|
|
969
135
|
baseSegments.pop();
|
|
970
136
|
}
|
|
971
|
-
|
|
972
137
|
baseSegments.pop();
|
|
973
138
|
} else if (toSegment.value === '.') {
|
|
974
139
|
return;
|
|
@@ -983,10 +148,8 @@ function parsePathname(pathname) {
|
|
|
983
148
|
if (!pathname) {
|
|
984
149
|
return [];
|
|
985
150
|
}
|
|
986
|
-
|
|
987
151
|
pathname = cleanPath(pathname);
|
|
988
152
|
const segments = [];
|
|
989
|
-
|
|
990
153
|
if (pathname.slice(0, 1) === '/') {
|
|
991
154
|
pathname = pathname.substring(1);
|
|
992
155
|
segments.push({
|
|
@@ -994,12 +157,11 @@ function parsePathname(pathname) {
|
|
|
994
157
|
value: '/'
|
|
995
158
|
});
|
|
996
159
|
}
|
|
997
|
-
|
|
998
160
|
if (!pathname) {
|
|
999
161
|
return segments;
|
|
1000
|
-
}
|
|
1001
|
-
|
|
162
|
+
}
|
|
1002
163
|
|
|
164
|
+
// Remove empty segments and '.' segments
|
|
1003
165
|
const split = pathname.split('/').filter(Boolean);
|
|
1004
166
|
segments.push(...split.map(part => {
|
|
1005
167
|
if (part.startsWith('*')) {
|
|
@@ -1008,20 +170,17 @@ function parsePathname(pathname) {
|
|
|
1008
170
|
value: part
|
|
1009
171
|
};
|
|
1010
172
|
}
|
|
1011
|
-
|
|
1012
173
|
if (part.charAt(0) === '$') {
|
|
1013
174
|
return {
|
|
1014
175
|
type: 'param',
|
|
1015
176
|
value: part
|
|
1016
177
|
};
|
|
1017
178
|
}
|
|
1018
|
-
|
|
1019
179
|
return {
|
|
1020
180
|
type: 'pathname',
|
|
1021
181
|
value: part
|
|
1022
182
|
};
|
|
1023
183
|
}));
|
|
1024
|
-
|
|
1025
184
|
if (pathname.slice(-1) === '/') {
|
|
1026
185
|
pathname = pathname.substring(1);
|
|
1027
186
|
segments.push({
|
|
@@ -1029,7 +188,6 @@ function parsePathname(pathname) {
|
|
|
1029
188
|
value: '/'
|
|
1030
189
|
});
|
|
1031
190
|
}
|
|
1032
|
-
|
|
1033
191
|
return segments;
|
|
1034
192
|
}
|
|
1035
193
|
function interpolatePath(path, params, leaveWildcard) {
|
|
@@ -1038,54 +196,45 @@ function interpolatePath(path, params, leaveWildcard) {
|
|
|
1038
196
|
if (segment.value === '*' && !leaveWildcard) {
|
|
1039
197
|
return '';
|
|
1040
198
|
}
|
|
1041
|
-
|
|
1042
199
|
if (segment.type === 'param') {
|
|
1043
200
|
var _segment$value$substr;
|
|
1044
|
-
|
|
1045
201
|
return (_segment$value$substr = params[segment.value.substring(1)]) != null ? _segment$value$substr : '';
|
|
1046
202
|
}
|
|
1047
|
-
|
|
1048
203
|
return segment.value;
|
|
1049
204
|
}));
|
|
1050
205
|
}
|
|
1051
206
|
function matchPathname(currentPathname, matchLocation) {
|
|
1052
|
-
const pathParams = matchByPath(currentPathname, matchLocation);
|
|
207
|
+
const pathParams = matchByPath(currentPathname, matchLocation);
|
|
208
|
+
// const searchMatched = matchBySearch(currentLocation.search, matchLocation)
|
|
1053
209
|
|
|
1054
210
|
if (matchLocation.to && !pathParams) {
|
|
1055
211
|
return;
|
|
1056
212
|
}
|
|
1057
|
-
|
|
1058
213
|
return pathParams != null ? pathParams : {};
|
|
1059
214
|
}
|
|
1060
215
|
function matchByPath(from, matchLocation) {
|
|
1061
216
|
var _matchLocation$to;
|
|
1062
|
-
|
|
1063
217
|
const baseSegments = parsePathname(from);
|
|
1064
218
|
const routeSegments = parsePathname("" + ((_matchLocation$to = matchLocation.to) != null ? _matchLocation$to : '*'));
|
|
1065
219
|
const params = {};
|
|
1066
|
-
|
|
1067
220
|
let isMatch = (() => {
|
|
1068
221
|
for (let i = 0; i < Math.max(baseSegments.length, routeSegments.length); i++) {
|
|
1069
222
|
const baseSegment = baseSegments[i];
|
|
1070
223
|
const routeSegment = routeSegments[i];
|
|
1071
224
|
const isLastRouteSegment = i === routeSegments.length - 1;
|
|
1072
225
|
const isLastBaseSegment = i === baseSegments.length - 1;
|
|
1073
|
-
|
|
1074
226
|
if (routeSegment) {
|
|
1075
227
|
if (routeSegment.type === 'wildcard') {
|
|
1076
228
|
if (baseSegment != null && baseSegment.value) {
|
|
1077
229
|
params['*'] = joinPaths(baseSegments.slice(i).map(d => d.value));
|
|
1078
230
|
return true;
|
|
1079
231
|
}
|
|
1080
|
-
|
|
1081
232
|
return false;
|
|
1082
233
|
}
|
|
1083
|
-
|
|
1084
234
|
if (routeSegment.type === 'pathname') {
|
|
1085
235
|
if (routeSegment.value === '/' && !(baseSegment != null && baseSegment.value)) {
|
|
1086
236
|
return true;
|
|
1087
237
|
}
|
|
1088
|
-
|
|
1089
238
|
if (baseSegment) {
|
|
1090
239
|
if (matchLocation.caseSensitive) {
|
|
1091
240
|
if (routeSegment.value !== baseSegment.value) {
|
|
@@ -1096,41 +245,36 @@ function matchByPath(from, matchLocation) {
|
|
|
1096
245
|
}
|
|
1097
246
|
}
|
|
1098
247
|
}
|
|
1099
|
-
|
|
1100
248
|
if (!baseSegment) {
|
|
1101
249
|
return false;
|
|
1102
250
|
}
|
|
1103
|
-
|
|
1104
251
|
if (routeSegment.type === 'param') {
|
|
1105
252
|
if ((baseSegment == null ? void 0 : baseSegment.value) === '/') {
|
|
1106
253
|
return false;
|
|
1107
254
|
}
|
|
1108
|
-
|
|
1109
255
|
if (baseSegment.value.charAt(0) !== '$') {
|
|
1110
256
|
params[routeSegment.value.substring(1)] = baseSegment.value;
|
|
1111
257
|
}
|
|
1112
258
|
}
|
|
1113
259
|
}
|
|
1114
|
-
|
|
1115
260
|
if (isLastRouteSegment && !isLastBaseSegment) {
|
|
1116
261
|
return !!matchLocation.fuzzy;
|
|
1117
262
|
}
|
|
1118
263
|
}
|
|
1119
|
-
|
|
1120
264
|
return true;
|
|
1121
265
|
})();
|
|
1122
|
-
|
|
1123
266
|
return isMatch ? params : undefined;
|
|
1124
267
|
}
|
|
1125
268
|
|
|
1126
269
|
// @ts-nocheck
|
|
270
|
+
|
|
1127
271
|
// 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.
|
|
272
|
+
|
|
1128
273
|
function encode(obj, pfx) {
|
|
1129
274
|
var k,
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
275
|
+
i,
|
|
276
|
+
tmp,
|
|
277
|
+
str = '';
|
|
1134
278
|
for (k in obj) {
|
|
1135
279
|
if ((tmp = obj[k]) !== void 0) {
|
|
1136
280
|
if (Array.isArray(tmp)) {
|
|
@@ -1144,10 +288,8 @@ function encode(obj, pfx) {
|
|
|
1144
288
|
}
|
|
1145
289
|
}
|
|
1146
290
|
}
|
|
1147
|
-
|
|
1148
291
|
return (pfx || '') + str;
|
|
1149
292
|
}
|
|
1150
|
-
|
|
1151
293
|
function toValue(mix) {
|
|
1152
294
|
if (!mix) return '';
|
|
1153
295
|
var str = decodeURIComponent(mix);
|
|
@@ -1156,24 +298,20 @@ function toValue(mix) {
|
|
|
1156
298
|
if (str.charAt(0) === '0') return str;
|
|
1157
299
|
return +str * 0 === 0 ? +str : str;
|
|
1158
300
|
}
|
|
1159
|
-
|
|
1160
301
|
function decode(str) {
|
|
1161
302
|
var tmp,
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
303
|
+
k,
|
|
304
|
+
out = {},
|
|
305
|
+
arr = str.split('&');
|
|
1166
306
|
while (tmp = arr.shift()) {
|
|
1167
307
|
tmp = tmp.split('=');
|
|
1168
308
|
k = tmp.shift();
|
|
1169
|
-
|
|
1170
309
|
if (out[k] !== void 0) {
|
|
1171
310
|
out[k] = [].concat(out[k], toValue(tmp.shift()));
|
|
1172
311
|
} else {
|
|
1173
312
|
out[k] = toValue(tmp.shift());
|
|
1174
313
|
}
|
|
1175
314
|
}
|
|
1176
|
-
|
|
1177
315
|
return out;
|
|
1178
316
|
}
|
|
1179
317
|
|
|
@@ -1181,14 +319,12 @@ function _extends() {
|
|
|
1181
319
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
1182
320
|
for (var i = 1; i < arguments.length; i++) {
|
|
1183
321
|
var source = arguments[i];
|
|
1184
|
-
|
|
1185
322
|
for (var key in source) {
|
|
1186
323
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1187
324
|
target[key] = source[key];
|
|
1188
325
|
}
|
|
1189
326
|
}
|
|
1190
327
|
}
|
|
1191
|
-
|
|
1192
328
|
return target;
|
|
1193
329
|
};
|
|
1194
330
|
return _extends.apply(this, arguments);
|
|
@@ -1201,23 +337,18 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1201
337
|
path: routePath,
|
|
1202
338
|
fullPath
|
|
1203
339
|
} = routeConfig;
|
|
1204
|
-
|
|
1205
340
|
const action = router.state.actions[id] || (() => {
|
|
1206
341
|
router.state.actions[id] = {
|
|
1207
342
|
submissions: [],
|
|
1208
343
|
submit: async (submission, actionOpts) => {
|
|
1209
344
|
var _actionOpts$invalidat;
|
|
1210
|
-
|
|
1211
345
|
if (!route) {
|
|
1212
346
|
return;
|
|
1213
347
|
}
|
|
1214
|
-
|
|
1215
348
|
const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
|
|
1216
|
-
|
|
1217
349
|
if (!(actionOpts != null && actionOpts.multi)) {
|
|
1218
350
|
action.submissions = action.submissions.filter(d => d.isMulti);
|
|
1219
351
|
}
|
|
1220
|
-
|
|
1221
352
|
const actionState = {
|
|
1222
353
|
submittedAt: Date.now(),
|
|
1223
354
|
status: 'pending',
|
|
@@ -1228,11 +359,9 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1228
359
|
action.latest = actionState;
|
|
1229
360
|
action.submissions.push(actionState);
|
|
1230
361
|
router.notify();
|
|
1231
|
-
|
|
1232
362
|
try {
|
|
1233
363
|
const res = await (route.options.action == null ? void 0 : route.options.action(submission));
|
|
1234
364
|
actionState.data = res;
|
|
1235
|
-
|
|
1236
365
|
if (invalidate) {
|
|
1237
366
|
router.invalidateRoute({
|
|
1238
367
|
to: '.',
|
|
@@ -1240,10 +369,10 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1240
369
|
});
|
|
1241
370
|
await router.reload();
|
|
1242
371
|
}
|
|
1243
|
-
|
|
1244
372
|
actionState.status = 'success';
|
|
1245
373
|
return res;
|
|
1246
374
|
} catch (err) {
|
|
375
|
+
console.log('tanner');
|
|
1247
376
|
console.error(err);
|
|
1248
377
|
actionState.error = err;
|
|
1249
378
|
actionState.status = 'error';
|
|
@@ -1254,7 +383,6 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1254
383
|
};
|
|
1255
384
|
return router.state.actions[id];
|
|
1256
385
|
})();
|
|
1257
|
-
|
|
1258
386
|
const loader = router.state.loaders[id] || (() => {
|
|
1259
387
|
router.state.loaders[id] = {
|
|
1260
388
|
pending: [],
|
|
@@ -1262,33 +390,32 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1262
390
|
if (!route) {
|
|
1263
391
|
return;
|
|
1264
392
|
}
|
|
1265
|
-
|
|
1266
393
|
const loaderState = {
|
|
1267
394
|
loadedAt: Date.now(),
|
|
1268
395
|
loaderContext
|
|
1269
396
|
};
|
|
1270
397
|
loader.current = loaderState;
|
|
1271
398
|
loader.latest = loaderState;
|
|
1272
|
-
loader.pending.push(loaderState);
|
|
399
|
+
loader.pending.push(loaderState);
|
|
400
|
+
|
|
401
|
+
// router.state = {
|
|
1273
402
|
// ...router.state,
|
|
1274
403
|
// currentAction: loaderState,
|
|
1275
404
|
// latestAction: loaderState,
|
|
1276
405
|
// }
|
|
1277
406
|
|
|
1278
407
|
router.notify();
|
|
1279
|
-
|
|
1280
408
|
try {
|
|
1281
409
|
return await (route.options.loader == null ? void 0 : route.options.loader(loaderContext));
|
|
1282
410
|
} finally {
|
|
1283
|
-
loader.pending = loader.pending.filter(d => d !== loaderState);
|
|
1284
|
-
|
|
411
|
+
loader.pending = loader.pending.filter(d => d !== loaderState);
|
|
412
|
+
// router.removeActionQueue.push({ loader, loaderState })
|
|
1285
413
|
router.notify();
|
|
1286
414
|
}
|
|
1287
415
|
}
|
|
1288
416
|
};
|
|
1289
417
|
return router.state.loaders[id];
|
|
1290
418
|
})();
|
|
1291
|
-
|
|
1292
419
|
let route = {
|
|
1293
420
|
routeInfo: undefined,
|
|
1294
421
|
routeId: id,
|
|
@@ -1329,37 +456,31 @@ const createRouteConfig = function createRouteConfig(options, children, isRoot,
|
|
|
1329
456
|
if (options === void 0) {
|
|
1330
457
|
options = {};
|
|
1331
458
|
}
|
|
1332
|
-
|
|
1333
459
|
if (isRoot === void 0) {
|
|
1334
460
|
isRoot = true;
|
|
1335
461
|
}
|
|
1336
|
-
|
|
1337
462
|
if (isRoot) {
|
|
1338
463
|
options.path = rootRouteId;
|
|
1339
|
-
}
|
|
1340
|
-
|
|
464
|
+
}
|
|
1341
465
|
|
|
466
|
+
// Strip the root from parentIds
|
|
1342
467
|
if (parentId === rootRouteId) {
|
|
1343
468
|
parentId = '';
|
|
1344
469
|
}
|
|
470
|
+
let path = isRoot ? rootRouteId : options.path;
|
|
1345
471
|
|
|
1346
|
-
|
|
1347
|
-
|
|
472
|
+
// If the path is anything other than an index path, trim it up
|
|
1348
473
|
if (path && path !== '/') {
|
|
1349
474
|
path = trimPath(path);
|
|
1350
475
|
}
|
|
1351
|
-
|
|
1352
476
|
const routeId = path || options.id;
|
|
1353
477
|
let id = joinPaths([parentId, routeId]);
|
|
1354
|
-
|
|
1355
478
|
if (path === rootRouteId) {
|
|
1356
479
|
path = '/';
|
|
1357
480
|
}
|
|
1358
|
-
|
|
1359
481
|
if (id !== rootRouteId) {
|
|
1360
482
|
id = joinPaths(['/', id]);
|
|
1361
483
|
}
|
|
1362
|
-
|
|
1363
484
|
const fullPath = id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]));
|
|
1364
485
|
return {
|
|
1365
486
|
id: id,
|
|
@@ -1400,31 +521,26 @@ function createRouteMatch(router, route, opts) {
|
|
|
1400
521
|
resolve: () => {},
|
|
1401
522
|
notify: () => {
|
|
1402
523
|
routeMatch.__.resolve();
|
|
1403
|
-
|
|
1404
524
|
routeMatch.router.notify();
|
|
1405
525
|
},
|
|
1406
526
|
validate: () => {
|
|
1407
527
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1408
|
-
|
|
1409
528
|
// Validate the search params and stabilize them
|
|
1410
529
|
const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
|
|
1411
|
-
|
|
1412
530
|
try {
|
|
1413
531
|
var _validator;
|
|
1414
|
-
|
|
1415
532
|
const prevSearch = routeMatch.routeSearch;
|
|
1416
533
|
const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
|
|
1417
|
-
let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {});
|
|
534
|
+
let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {});
|
|
1418
535
|
|
|
536
|
+
// Invalidate route matches when search param stability changes
|
|
1419
537
|
if (prevSearch !== nextSearch) {
|
|
1420
538
|
routeMatch.isInvalid = true;
|
|
1421
539
|
}
|
|
1422
|
-
|
|
1423
540
|
routeMatch.routeSearch = nextSearch;
|
|
1424
541
|
routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
|
|
1425
542
|
componentTypes.map(async type => {
|
|
1426
543
|
const component = routeMatch.options[type];
|
|
1427
|
-
|
|
1428
544
|
if (typeof routeMatch.__[type] !== 'function') {
|
|
1429
545
|
routeMatch.__[type] = component;
|
|
1430
546
|
}
|
|
@@ -1436,15 +552,14 @@ function createRouteMatch(router, route, opts) {
|
|
|
1436
552
|
});
|
|
1437
553
|
error.code = 'INVALID_SEARCH_PARAMS';
|
|
1438
554
|
routeMatch.status = 'error';
|
|
1439
|
-
routeMatch.error = error;
|
|
1440
|
-
|
|
555
|
+
routeMatch.error = error;
|
|
556
|
+
// Do not proceed with loading the route
|
|
1441
557
|
return;
|
|
1442
558
|
}
|
|
1443
559
|
}
|
|
1444
560
|
},
|
|
1445
561
|
cancel: () => {
|
|
1446
562
|
var _routeMatch$__$abortC;
|
|
1447
|
-
|
|
1448
563
|
(_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
|
|
1449
564
|
},
|
|
1450
565
|
invalidate: () => {
|
|
@@ -1453,27 +568,26 @@ function createRouteMatch(router, route, opts) {
|
|
|
1453
568
|
hasLoaders: () => {
|
|
1454
569
|
return !!(route.options.loader || componentTypes.some(d => {
|
|
1455
570
|
var _route$options$d;
|
|
1456
|
-
|
|
1457
571
|
return (_route$options$d = route.options[d]) == null ? void 0 : _route$options$d.preload;
|
|
1458
572
|
}));
|
|
1459
573
|
},
|
|
1460
574
|
load: async loaderOpts => {
|
|
1461
575
|
const now = Date.now();
|
|
1462
|
-
const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0;
|
|
576
|
+
const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0;
|
|
1463
577
|
|
|
578
|
+
// If this is a preload, add it to the preload cache
|
|
1464
579
|
if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
|
|
1465
580
|
// If the match is currently active, don't preload it
|
|
1466
581
|
if (router.state.matches.find(d => d.matchId === routeMatch.matchId)) {
|
|
1467
582
|
return;
|
|
1468
583
|
}
|
|
1469
|
-
|
|
1470
584
|
router.matchCache[routeMatch.matchId] = {
|
|
1471
585
|
gc: now + loaderOpts.gcMaxAge,
|
|
1472
586
|
match: routeMatch
|
|
1473
587
|
};
|
|
1474
|
-
}
|
|
1475
|
-
|
|
588
|
+
}
|
|
1476
589
|
|
|
590
|
+
// If the match is invalid, errored or idle, trigger it to load
|
|
1477
591
|
if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
|
|
1478
592
|
const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
|
|
1479
593
|
await routeMatch.fetch({
|
|
@@ -1484,53 +598,47 @@ function createRouteMatch(router, route, opts) {
|
|
|
1484
598
|
fetch: async opts => {
|
|
1485
599
|
const loadId = '' + Date.now() + Math.random();
|
|
1486
600
|
routeMatch.__.latestId = loadId;
|
|
1487
|
-
|
|
1488
601
|
const checkLatest = async () => {
|
|
1489
602
|
if (loadId !== routeMatch.__.latestId) {
|
|
1490
603
|
// warning(true, 'Data loader is out of date!')
|
|
1491
604
|
return new Promise(() => {});
|
|
1492
605
|
}
|
|
1493
|
-
};
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
// If the match was in an error state, set it
|
|
1494
609
|
// to a loading state again. Otherwise, keep it
|
|
1495
610
|
// as loading or resolved
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
611
|
if (routeMatch.status === 'idle') {
|
|
1499
612
|
routeMatch.status = 'loading';
|
|
1500
|
-
}
|
|
1501
|
-
|
|
613
|
+
}
|
|
1502
614
|
|
|
615
|
+
// We started loading the route, so it's no longer invalid
|
|
1503
616
|
routeMatch.isInvalid = false;
|
|
1504
617
|
routeMatch.__.loadPromise = new Promise(async resolve => {
|
|
1505
618
|
// We are now fetching, even if it's in the background of a
|
|
1506
619
|
// resolved state
|
|
1507
620
|
routeMatch.isFetching = true;
|
|
1508
621
|
routeMatch.__.resolve = resolve;
|
|
1509
|
-
|
|
1510
622
|
routeMatch.__.componentsPromise = (async () => {
|
|
1511
623
|
// then run all component and data loaders in parallel
|
|
1512
624
|
// For each component type, potentially load it asynchronously
|
|
625
|
+
|
|
1513
626
|
await Promise.all(componentTypes.map(async type => {
|
|
1514
627
|
var _routeMatch$__$type;
|
|
1515
|
-
|
|
1516
628
|
const component = routeMatch.options[type];
|
|
1517
|
-
|
|
1518
629
|
if ((_routeMatch$__$type = routeMatch.__[type]) != null && _routeMatch$__$type.preload) {
|
|
1519
630
|
routeMatch.__[type] = await router.options.loadComponent(component);
|
|
1520
631
|
}
|
|
1521
632
|
}));
|
|
1522
633
|
})();
|
|
1523
|
-
|
|
1524
634
|
routeMatch.__.dataPromise = Promise.resolve().then(async () => {
|
|
1525
635
|
try {
|
|
1526
636
|
var _ref, _ref2, _opts$maxAge;
|
|
1527
|
-
|
|
1528
637
|
if (routeMatch.options.loader) {
|
|
1529
638
|
const data = await router.loadMatchData(routeMatch);
|
|
1530
639
|
await checkLatest();
|
|
1531
640
|
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1532
641
|
}
|
|
1533
|
-
|
|
1534
642
|
routeMatch.error = undefined;
|
|
1535
643
|
routeMatch.status = 'success';
|
|
1536
644
|
routeMatch.updatedAt = Date.now();
|
|
@@ -1538,26 +646,21 @@ function createRouteMatch(router, route, opts) {
|
|
|
1538
646
|
return routeMatch.routeLoaderData;
|
|
1539
647
|
} catch (err) {
|
|
1540
648
|
await checkLatest();
|
|
1541
|
-
|
|
1542
649
|
if (process.env.NODE_ENV !== 'production') {
|
|
1543
650
|
console.error(err);
|
|
1544
651
|
}
|
|
1545
|
-
|
|
1546
652
|
routeMatch.error = err;
|
|
1547
653
|
routeMatch.status = 'error';
|
|
1548
654
|
routeMatch.updatedAt = Date.now();
|
|
1549
655
|
throw err;
|
|
1550
656
|
}
|
|
1551
657
|
});
|
|
1552
|
-
|
|
1553
658
|
const after = async () => {
|
|
1554
659
|
await checkLatest();
|
|
1555
660
|
routeMatch.isFetching = false;
|
|
1556
661
|
delete routeMatch.__.loadPromise;
|
|
1557
|
-
|
|
1558
662
|
routeMatch.__.notify();
|
|
1559
663
|
};
|
|
1560
|
-
|
|
1561
664
|
try {
|
|
1562
665
|
await Promise.all([routeMatch.__.componentsPromise, routeMatch.__.dataPromise.catch(() => {})]);
|
|
1563
666
|
after();
|
|
@@ -1569,11 +672,9 @@ function createRouteMatch(router, route, opts) {
|
|
|
1569
672
|
await checkLatest();
|
|
1570
673
|
}
|
|
1571
674
|
});
|
|
1572
|
-
|
|
1573
675
|
if (!routeMatch.hasLoaders()) {
|
|
1574
676
|
routeMatch.status = 'success';
|
|
1575
677
|
}
|
|
1576
|
-
|
|
1577
678
|
return routeMatch;
|
|
1578
679
|
}
|
|
1579
680
|
|
|
@@ -1584,42 +685,39 @@ function parseSearchWith(parser) {
|
|
|
1584
685
|
if (searchStr.substring(0, 1) === '?') {
|
|
1585
686
|
searchStr = searchStr.substring(1);
|
|
1586
687
|
}
|
|
688
|
+
let query = decode(searchStr);
|
|
1587
689
|
|
|
1588
|
-
|
|
1589
|
-
|
|
690
|
+
// Try to parse any query params that might be json
|
|
1590
691
|
for (let key in query) {
|
|
1591
692
|
const value = query[key];
|
|
1592
|
-
|
|
1593
693
|
if (typeof value === 'string') {
|
|
1594
694
|
try {
|
|
1595
695
|
query[key] = parser(value);
|
|
1596
|
-
} catch (err) {
|
|
696
|
+
} catch (err) {
|
|
697
|
+
//
|
|
1597
698
|
}
|
|
1598
699
|
}
|
|
1599
700
|
}
|
|
1600
|
-
|
|
1601
701
|
return query;
|
|
1602
702
|
};
|
|
1603
703
|
}
|
|
1604
704
|
function stringifySearchWith(stringify) {
|
|
1605
705
|
return search => {
|
|
1606
706
|
search = _extends({}, search);
|
|
1607
|
-
|
|
1608
707
|
if (search) {
|
|
1609
708
|
Object.keys(search).forEach(key => {
|
|
1610
709
|
const val = search[key];
|
|
1611
|
-
|
|
1612
710
|
if (typeof val === 'undefined' || val === undefined) {
|
|
1613
711
|
delete search[key];
|
|
1614
712
|
} else if (val && typeof val === 'object' && val !== null) {
|
|
1615
713
|
try {
|
|
1616
714
|
search[key] = stringify(val);
|
|
1617
|
-
} catch (err) {
|
|
715
|
+
} catch (err) {
|
|
716
|
+
// silent
|
|
1618
717
|
}
|
|
1619
718
|
}
|
|
1620
719
|
});
|
|
1621
720
|
}
|
|
1622
|
-
|
|
1623
721
|
const searchStr = encode(search).toString();
|
|
1624
722
|
return searchStr ? "?" + searchStr : '';
|
|
1625
723
|
};
|
|
@@ -1627,10 +725,10 @@ function stringifySearchWith(stringify) {
|
|
|
1627
725
|
|
|
1628
726
|
var _window$document;
|
|
1629
727
|
// Detect if we're in the DOM
|
|
1630
|
-
const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement);
|
|
728
|
+
const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement);
|
|
1631
729
|
|
|
730
|
+
// This is the default history object if none is defined
|
|
1632
731
|
const createDefaultHistory = () => isServer ? createMemoryHistory() : createBrowserHistory();
|
|
1633
|
-
|
|
1634
732
|
function getInitialRouterState() {
|
|
1635
733
|
return {
|
|
1636
734
|
status: 'idle',
|
|
@@ -1643,22 +741,19 @@ function getInitialRouterState() {
|
|
|
1643
741
|
isPreloading: false
|
|
1644
742
|
};
|
|
1645
743
|
}
|
|
1646
|
-
|
|
1647
744
|
function createRouter(userOptions) {
|
|
1648
745
|
var _userOptions$stringif, _userOptions$parseSea;
|
|
1649
|
-
|
|
1650
746
|
const history = (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory();
|
|
1651
|
-
|
|
1652
747
|
const originalOptions = _extends({
|
|
1653
748
|
defaultLoaderGcMaxAge: 5 * 60 * 1000,
|
|
1654
749
|
defaultLoaderMaxAge: 0,
|
|
1655
750
|
defaultPreloadMaxAge: 2000,
|
|
1656
|
-
defaultPreloadDelay: 50
|
|
751
|
+
defaultPreloadDelay: 50,
|
|
752
|
+
context: undefined
|
|
1657
753
|
}, userOptions, {
|
|
1658
754
|
stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
|
|
1659
755
|
parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
|
|
1660
756
|
});
|
|
1661
|
-
|
|
1662
757
|
let router = {
|
|
1663
758
|
types: undefined,
|
|
1664
759
|
// public api
|
|
@@ -1666,13 +761,11 @@ function createRouter(userOptions) {
|
|
|
1666
761
|
options: originalOptions,
|
|
1667
762
|
listeners: [],
|
|
1668
763
|
// Resolved after construction
|
|
1669
|
-
context: {},
|
|
1670
764
|
basepath: '',
|
|
1671
765
|
routeTree: undefined,
|
|
1672
766
|
routesById: {},
|
|
1673
767
|
location: undefined,
|
|
1674
768
|
//
|
|
1675
|
-
navigationPromise: Promise.resolve(),
|
|
1676
769
|
resolveNavigation: () => {},
|
|
1677
770
|
matchCache: {},
|
|
1678
771
|
state: getInitialRouterState(),
|
|
@@ -1693,29 +786,37 @@ function createRouter(userOptions) {
|
|
|
1693
786
|
notify: () => {
|
|
1694
787
|
const isFetching = router.state.status === 'loading' || router.state.matches.some(d => d.isFetching);
|
|
1695
788
|
const isPreloading = Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId));
|
|
1696
|
-
|
|
1697
789
|
if (router.state.isFetching !== isFetching || router.state.isPreloading !== isPreloading) {
|
|
1698
790
|
router.state = _extends({}, router.state, {
|
|
1699
791
|
isFetching,
|
|
1700
792
|
isPreloading
|
|
1701
793
|
});
|
|
1702
794
|
}
|
|
1703
|
-
|
|
1704
795
|
cascadeLoaderData(router.state.matches);
|
|
1705
796
|
router.listeners.forEach(listener => listener(router));
|
|
1706
797
|
},
|
|
1707
|
-
|
|
1708
|
-
return
|
|
1709
|
-
|
|
1710
|
-
|
|
798
|
+
dehydrate: () => {
|
|
799
|
+
return {
|
|
800
|
+
location: router.location,
|
|
801
|
+
state: _extends({}, pick(router.state, ['status', 'location', 'lastUpdated', 'location']), {
|
|
802
|
+
matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
|
|
803
|
+
}),
|
|
804
|
+
context: router.options.context
|
|
805
|
+
};
|
|
1711
806
|
},
|
|
1712
|
-
|
|
807
|
+
hydrate: dehydratedState => {
|
|
808
|
+
// Update the location
|
|
809
|
+
router.location = dehydratedState.location;
|
|
810
|
+
|
|
811
|
+
// Update the context
|
|
812
|
+
router.options.context = dehydratedState.context;
|
|
813
|
+
|
|
1713
814
|
// Match the routes
|
|
1714
815
|
const matches = router.matchRoutes(router.location.pathname, {
|
|
1715
816
|
strictParseParams: true
|
|
1716
817
|
});
|
|
1717
818
|
matches.forEach((match, index) => {
|
|
1718
|
-
const dehydratedMatch = dehydratedState.matches[index];
|
|
819
|
+
const dehydratedMatch = dehydratedState.state.matches[index];
|
|
1719
820
|
invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
|
|
1720
821
|
Object.assign(match, dehydratedMatch);
|
|
1721
822
|
});
|
|
@@ -1729,32 +830,29 @@ function createRouter(userOptions) {
|
|
|
1729
830
|
to: '.',
|
|
1730
831
|
search: true,
|
|
1731
832
|
hash: true
|
|
1732
|
-
});
|
|
1733
|
-
// to the current location. Otherwise, load the current location.
|
|
1734
|
-
|
|
833
|
+
});
|
|
1735
834
|
|
|
835
|
+
// If the current location isn't updated, trigger a navigation
|
|
836
|
+
// to the current location. Otherwise, load the current location.
|
|
1736
837
|
if (next.href !== router.location.href) {
|
|
1737
838
|
router.__.commitLocation(next, true);
|
|
1738
839
|
}
|
|
1739
|
-
|
|
1740
840
|
if (!router.state.matches.length) {
|
|
1741
841
|
router.load();
|
|
1742
842
|
}
|
|
1743
|
-
|
|
1744
843
|
const unsub = router.history.listen(event => {
|
|
1745
844
|
router.load(router.__.parseLocation(event.location, router.location));
|
|
1746
|
-
});
|
|
1747
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
845
|
+
});
|
|
1748
846
|
|
|
847
|
+
// addEventListener does not exist in React Native, but window does
|
|
848
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1749
849
|
if (!isServer && window.addEventListener) {
|
|
1750
850
|
// Listen to visibillitychange and focus
|
|
1751
851
|
window.addEventListener('visibilitychange', router.onFocus, false);
|
|
1752
852
|
window.addEventListener('focus', router.onFocus, false);
|
|
1753
853
|
}
|
|
1754
|
-
|
|
1755
854
|
return () => {
|
|
1756
855
|
unsub();
|
|
1757
|
-
|
|
1758
856
|
if (!isServer && window.removeEventListener) {
|
|
1759
857
|
// Be sure to unsubscribe if a new handler is set
|
|
1760
858
|
window.removeEventListener('visibilitychange', router.onFocus);
|
|
@@ -1767,28 +865,23 @@ function createRouter(userOptions) {
|
|
|
1767
865
|
},
|
|
1768
866
|
update: opts => {
|
|
1769
867
|
const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
|
|
1770
|
-
|
|
1771
868
|
if (!router.location || newHistory) {
|
|
1772
869
|
if (opts != null && opts.history) {
|
|
1773
870
|
router.history = opts.history;
|
|
1774
871
|
}
|
|
1775
|
-
|
|
1776
872
|
router.location = router.__.parseLocation(router.history.location);
|
|
1777
873
|
router.state.location = router.location;
|
|
1778
874
|
}
|
|
1779
|
-
|
|
1780
875
|
Object.assign(router.options, opts);
|
|
1781
876
|
const {
|
|
1782
877
|
basepath,
|
|
1783
878
|
routeConfig
|
|
1784
879
|
} = router.options;
|
|
1785
880
|
router.basepath = cleanPath("/" + (basepath != null ? basepath : ''));
|
|
1786
|
-
|
|
1787
881
|
if (routeConfig) {
|
|
1788
882
|
router.routesById = {};
|
|
1789
883
|
router.routeTree = router.__.buildRouteTree(routeConfig);
|
|
1790
884
|
}
|
|
1791
|
-
|
|
1792
885
|
return router;
|
|
1793
886
|
},
|
|
1794
887
|
cancelMatches: () => {
|
|
@@ -1800,31 +893,18 @@ function createRouter(userOptions) {
|
|
|
1800
893
|
load: async next => {
|
|
1801
894
|
const id = Math.random();
|
|
1802
895
|
router.startedLoadingAt = id;
|
|
1803
|
-
|
|
1804
896
|
if (next) {
|
|
1805
897
|
// Ingest the new location
|
|
1806
898
|
router.location = next;
|
|
1807
|
-
}
|
|
1808
|
-
|
|
899
|
+
}
|
|
1809
900
|
|
|
1810
|
-
|
|
901
|
+
// Cancel any pending matches
|
|
902
|
+
router.cancelMatches();
|
|
1811
903
|
|
|
904
|
+
// Match the routes
|
|
1812
905
|
const matches = router.matchRoutes(router.location.pathname, {
|
|
1813
906
|
strictParseParams: true
|
|
1814
|
-
});
|
|
1815
|
-
|
|
1816
|
-
try {
|
|
1817
|
-
await Promise.all(matches.map(match => match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
|
|
1818
|
-
context: router.context
|
|
1819
|
-
})));
|
|
1820
|
-
} catch (err) {
|
|
1821
|
-
if (err != null && err.then) {
|
|
1822
|
-
await new Promise(() => {});
|
|
1823
|
-
}
|
|
1824
|
-
|
|
1825
|
-
throw err;
|
|
1826
|
-
}
|
|
1827
|
-
|
|
907
|
+
});
|
|
1828
908
|
if (typeof document !== 'undefined') {
|
|
1829
909
|
router.state = _extends({}, router.state, {
|
|
1830
910
|
pending: {
|
|
@@ -1841,18 +921,29 @@ function createRouter(userOptions) {
|
|
|
1841
921
|
});
|
|
1842
922
|
}
|
|
1843
923
|
|
|
1844
|
-
|
|
924
|
+
// Check if each match middleware to see if the route can be accessed
|
|
925
|
+
try {
|
|
926
|
+
await Promise.all(matches.map(match => match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
|
|
927
|
+
router: router,
|
|
928
|
+
match
|
|
929
|
+
})));
|
|
930
|
+
} catch (err) {
|
|
931
|
+
if (err != null && err.then) {
|
|
932
|
+
await new Promise(() => {});
|
|
933
|
+
}
|
|
934
|
+
throw err;
|
|
935
|
+
}
|
|
936
|
+
router.notify();
|
|
1845
937
|
|
|
938
|
+
// Load the matches
|
|
1846
939
|
await router.loadMatches(matches);
|
|
1847
|
-
|
|
1848
940
|
if (router.startedLoadingAt !== id) {
|
|
1849
941
|
// Ignore side-effects of match loading
|
|
1850
942
|
return router.navigationPromise;
|
|
1851
943
|
}
|
|
1852
|
-
|
|
1853
944
|
const previousMatches = router.state.matches;
|
|
1854
945
|
const exiting = [],
|
|
1855
|
-
|
|
946
|
+
staying = [];
|
|
1856
947
|
previousMatches.forEach(d => {
|
|
1857
948
|
if (matches.find(dd => dd.matchId === d.matchId)) {
|
|
1858
949
|
staying.push(d);
|
|
@@ -1866,19 +957,17 @@ function createRouter(userOptions) {
|
|
|
1866
957
|
const now = Date.now();
|
|
1867
958
|
exiting.forEach(d => {
|
|
1868
959
|
var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
|
|
1869
|
-
|
|
1870
960
|
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
1871
961
|
params: d.params,
|
|
1872
962
|
search: d.routeSearch
|
|
1873
|
-
});
|
|
963
|
+
});
|
|
1874
964
|
|
|
965
|
+
// Clear idle error states when match leaves
|
|
1875
966
|
if (d.status === 'error' && !d.isFetching) {
|
|
1876
967
|
d.status = 'idle';
|
|
1877
968
|
d.error = undefined;
|
|
1878
969
|
}
|
|
1879
|
-
|
|
1880
970
|
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);
|
|
1881
|
-
|
|
1882
971
|
if (gc > 0) {
|
|
1883
972
|
router.matchCache[d.matchId] = {
|
|
1884
973
|
gc: gc == Infinity ? Number.MAX_SAFE_INTEGER : now + gc,
|
|
@@ -1899,12 +988,10 @@ function createRouter(userOptions) {
|
|
|
1899
988
|
});
|
|
1900
989
|
delete router.matchCache[d.matchId];
|
|
1901
990
|
});
|
|
1902
|
-
|
|
1903
991
|
if (router.startedLoadingAt !== id) {
|
|
1904
992
|
// Ignore side-effects of match loading
|
|
1905
993
|
return;
|
|
1906
994
|
}
|
|
1907
|
-
|
|
1908
995
|
matches.forEach(match => {
|
|
1909
996
|
// Clear actions
|
|
1910
997
|
if (match.action) {
|
|
@@ -1924,18 +1011,19 @@ function createRouter(userOptions) {
|
|
|
1924
1011
|
cleanMatchCache: () => {
|
|
1925
1012
|
const now = Date.now();
|
|
1926
1013
|
Object.keys(router.matchCache).forEach(matchId => {
|
|
1927
|
-
const entry = router.matchCache[matchId];
|
|
1014
|
+
const entry = router.matchCache[matchId];
|
|
1928
1015
|
|
|
1016
|
+
// Don't remove loading matches
|
|
1929
1017
|
if (entry.match.status === 'loading') {
|
|
1930
1018
|
return;
|
|
1931
|
-
}
|
|
1932
|
-
|
|
1019
|
+
}
|
|
1933
1020
|
|
|
1021
|
+
// Do not remove successful matches that are still valid
|
|
1934
1022
|
if (entry.gc > 0 && entry.gc > now) {
|
|
1935
1023
|
return;
|
|
1936
|
-
}
|
|
1937
|
-
|
|
1024
|
+
}
|
|
1938
1025
|
|
|
1026
|
+
// Everything else gets removed
|
|
1939
1027
|
delete router.matchCache[matchId];
|
|
1940
1028
|
});
|
|
1941
1029
|
},
|
|
@@ -1943,7 +1031,6 @@ function createRouter(userOptions) {
|
|
|
1943
1031
|
if (navigateOpts === void 0) {
|
|
1944
1032
|
navigateOpts = router.location;
|
|
1945
1033
|
}
|
|
1946
|
-
|
|
1947
1034
|
const next = router.buildNext(navigateOpts);
|
|
1948
1035
|
const matches = router.matchRoutes(next.pathname, {
|
|
1949
1036
|
strictParseParams: true
|
|
@@ -1953,11 +1040,9 @@ function createRouter(userOptions) {
|
|
|
1953
1040
|
},
|
|
1954
1041
|
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
1955
1042
|
var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
|
|
1956
|
-
|
|
1957
1043
|
if (navigateOpts === void 0) {
|
|
1958
1044
|
navigateOpts = router.location;
|
|
1959
1045
|
}
|
|
1960
|
-
|
|
1961
1046
|
const next = router.buildNext(navigateOpts);
|
|
1962
1047
|
const matches = router.matchRoutes(next.pathname, {
|
|
1963
1048
|
strictParseParams: true
|
|
@@ -1971,90 +1056,70 @@ function createRouter(userOptions) {
|
|
|
1971
1056
|
},
|
|
1972
1057
|
matchRoutes: (pathname, opts) => {
|
|
1973
1058
|
var _router$state$pending3, _router$state$pending4;
|
|
1974
|
-
|
|
1975
1059
|
router.cleanMatchCache();
|
|
1976
1060
|
const matches = [];
|
|
1977
|
-
|
|
1978
1061
|
if (!router.routeTree) {
|
|
1979
1062
|
return matches;
|
|
1980
1063
|
}
|
|
1981
|
-
|
|
1982
1064
|
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 : [])];
|
|
1983
|
-
|
|
1984
1065
|
const recurse = async routes => {
|
|
1985
1066
|
var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
|
|
1986
|
-
|
|
1987
1067
|
const parentMatch = last(matches);
|
|
1988
1068
|
let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
|
|
1989
1069
|
const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
|
|
1990
1070
|
let foundRoutes = [];
|
|
1991
|
-
|
|
1992
1071
|
const findMatchInRoutes = (parentRoutes, routes) => {
|
|
1993
1072
|
routes.some(route => {
|
|
1994
1073
|
var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
|
|
1995
|
-
|
|
1996
1074
|
if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
|
|
1997
1075
|
return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
|
|
1998
1076
|
}
|
|
1999
|
-
|
|
2000
1077
|
const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
|
|
2001
1078
|
const matchParams = matchPathname(pathname, {
|
|
2002
1079
|
to: route.fullPath,
|
|
2003
1080
|
fuzzy,
|
|
2004
1081
|
caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
|
|
2005
1082
|
});
|
|
2006
|
-
|
|
2007
1083
|
if (matchParams) {
|
|
2008
1084
|
let parsedParams;
|
|
2009
|
-
|
|
2010
1085
|
try {
|
|
2011
1086
|
var _route$options$parseP;
|
|
2012
|
-
|
|
2013
1087
|
parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
|
|
2014
1088
|
} catch (err) {
|
|
2015
1089
|
if (opts != null && opts.strictParseParams) {
|
|
2016
1090
|
throw err;
|
|
2017
1091
|
}
|
|
2018
1092
|
}
|
|
2019
|
-
|
|
2020
1093
|
params = _extends({}, params, parsedParams);
|
|
2021
1094
|
}
|
|
2022
|
-
|
|
2023
1095
|
if (!!matchParams) {
|
|
2024
1096
|
foundRoutes = [...parentRoutes, route];
|
|
2025
1097
|
}
|
|
2026
|
-
|
|
2027
1098
|
return !!foundRoutes.length;
|
|
2028
1099
|
});
|
|
2029
1100
|
return !!foundRoutes.length;
|
|
2030
1101
|
};
|
|
2031
|
-
|
|
2032
1102
|
findMatchInRoutes([], filteredRoutes);
|
|
2033
|
-
|
|
2034
1103
|
if (!foundRoutes.length) {
|
|
2035
1104
|
return;
|
|
2036
1105
|
}
|
|
2037
|
-
|
|
2038
1106
|
foundRoutes.forEach(foundRoute => {
|
|
2039
1107
|
var _router$matchCache$ma;
|
|
2040
|
-
|
|
2041
1108
|
const interpolatedPath = interpolatePath(foundRoute.routePath, params);
|
|
2042
1109
|
const matchId = interpolatePath(foundRoute.routeId, params, true);
|
|
2043
1110
|
const match = existingMatches.find(d => d.matchId === matchId) || ((_router$matchCache$ma = router.matchCache[matchId]) == null ? void 0 : _router$matchCache$ma.match) || createRouteMatch(router, foundRoute, {
|
|
2044
1111
|
parentMatch,
|
|
2045
1112
|
matchId,
|
|
2046
1113
|
params,
|
|
2047
|
-
pathname: joinPaths([
|
|
1114
|
+
pathname: joinPaths([router.basepath, interpolatedPath])
|
|
2048
1115
|
});
|
|
2049
1116
|
matches.push(match);
|
|
2050
1117
|
});
|
|
2051
1118
|
const foundRoute = last(foundRoutes);
|
|
2052
|
-
|
|
2053
1119
|
if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
|
|
2054
1120
|
recurse(foundRoute.childRoutes);
|
|
2055
1121
|
}
|
|
2056
1122
|
};
|
|
2057
|
-
|
|
2058
1123
|
recurse([router.routeTree]);
|
|
2059
1124
|
cascadeLoaderData(matches);
|
|
2060
1125
|
return matches;
|
|
@@ -2063,14 +1128,11 @@ function createRouter(userOptions) {
|
|
|
2063
1128
|
const matchPromises = resolvedMatches.map(async match => {
|
|
2064
1129
|
// Validate the match (loads search params etc)
|
|
2065
1130
|
match.__.validate();
|
|
2066
|
-
|
|
2067
1131
|
match.load(loaderOpts);
|
|
2068
1132
|
const search = match.search;
|
|
2069
|
-
|
|
2070
1133
|
if (search.__data && search.__data.matchId !== match.matchId) {
|
|
2071
1134
|
return;
|
|
2072
1135
|
}
|
|
2073
|
-
|
|
2074
1136
|
if (match.__.loadPromise) {
|
|
2075
1137
|
// Wait for the first sign of activity from the match
|
|
2076
1138
|
await match.__.loadPromise;
|
|
@@ -2082,7 +1144,6 @@ function createRouter(userOptions) {
|
|
|
2082
1144
|
loadMatchData: async routeMatch => {
|
|
2083
1145
|
if (isServer || !router.options.useServerData) {
|
|
2084
1146
|
var _await$routeMatch$opt;
|
|
2085
|
-
|
|
2086
1147
|
return (_await$routeMatch$opt = await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
|
|
2087
1148
|
// parentLoaderPromise: routeMatch.parentMatch?.__.dataPromise,
|
|
2088
1149
|
params: routeMatch.params,
|
|
@@ -2098,21 +1159,30 @@ function createRouter(userOptions) {
|
|
|
2098
1159
|
}
|
|
2099
1160
|
})
|
|
2100
1161
|
});
|
|
2101
|
-
const res = await fetch(next.href, {
|
|
2102
|
-
method: 'GET' // signal: routeMatch.__.abortController.signal,
|
|
2103
1162
|
|
|
1163
|
+
// Refresh:
|
|
1164
|
+
// '/dashboard'
|
|
1165
|
+
// '/dashboard/invoices/'
|
|
1166
|
+
// '/dashboard/invoices/123'
|
|
1167
|
+
|
|
1168
|
+
// New:
|
|
1169
|
+
// '/dashboard/invoices/456'
|
|
1170
|
+
|
|
1171
|
+
// TODO: batch requests when possible
|
|
1172
|
+
|
|
1173
|
+
const res = await fetch(next.href, {
|
|
1174
|
+
method: 'GET'
|
|
1175
|
+
// signal: routeMatch.__.abortController.signal,
|
|
2104
1176
|
});
|
|
2105
1177
|
|
|
2106
1178
|
if (res.ok) {
|
|
2107
1179
|
return res.json();
|
|
2108
1180
|
}
|
|
2109
|
-
|
|
2110
1181
|
throw new Error('Failed to fetch match data');
|
|
2111
1182
|
}
|
|
2112
1183
|
},
|
|
2113
1184
|
invalidateRoute: opts => {
|
|
2114
1185
|
var _router$state$pending5, _router$state$pending6;
|
|
2115
|
-
|
|
2116
1186
|
const next = router.buildNext(opts);
|
|
2117
1187
|
const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
|
|
2118
1188
|
[...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 => {
|
|
@@ -2131,25 +1201,21 @@ function createRouter(userOptions) {
|
|
|
2131
1201
|
},
|
|
2132
1202
|
matchRoute: (location, opts) => {
|
|
2133
1203
|
var _location$from;
|
|
2134
|
-
|
|
2135
1204
|
// const location = router.buildNext(opts)
|
|
1205
|
+
|
|
2136
1206
|
location = _extends({}, location, {
|
|
2137
1207
|
to: location.to ? router.resolvePath((_location$from = location.from) != null ? _location$from : '', location.to) : undefined
|
|
2138
1208
|
});
|
|
2139
1209
|
const next = router.buildNext(location);
|
|
2140
|
-
|
|
2141
1210
|
if (opts != null && opts.pending) {
|
|
2142
1211
|
var _router$state$pending7;
|
|
2143
|
-
|
|
2144
1212
|
if (!((_router$state$pending7 = router.state.pending) != null && _router$state$pending7.location)) {
|
|
2145
1213
|
return false;
|
|
2146
1214
|
}
|
|
2147
|
-
|
|
2148
1215
|
return !!matchPathname(router.state.pending.location.pathname, _extends({}, opts, {
|
|
2149
1216
|
to: next.pathname
|
|
2150
1217
|
}));
|
|
2151
1218
|
}
|
|
2152
|
-
|
|
2153
1219
|
return !!matchPathname(router.state.location.pathname, _extends({}, opts, {
|
|
2154
1220
|
to: next.pathname
|
|
2155
1221
|
}));
|
|
@@ -2165,17 +1231,16 @@ function createRouter(userOptions) {
|
|
|
2165
1231
|
} = _ref7;
|
|
2166
1232
|
// If this link simply reloads the current route,
|
|
2167
1233
|
// make sure it has a new key so it will trigger a data refresh
|
|
1234
|
+
|
|
2168
1235
|
// If this `to` is a valid external URL, return
|
|
2169
1236
|
// null for LinkUtils
|
|
2170
1237
|
const toString = String(to);
|
|
2171
1238
|
const fromString = String(from);
|
|
2172
1239
|
let isExternal;
|
|
2173
|
-
|
|
2174
1240
|
try {
|
|
2175
1241
|
new URL("" + toString);
|
|
2176
1242
|
isExternal = true;
|
|
2177
1243
|
} catch (e) {}
|
|
2178
|
-
|
|
2179
1244
|
invariant(!isExternal, 'Attempting to navigate to external url with router.navigate!');
|
|
2180
1245
|
return router.__.navigate({
|
|
2181
1246
|
from: fromString,
|
|
@@ -2188,7 +1253,6 @@ function createRouter(userOptions) {
|
|
|
2188
1253
|
},
|
|
2189
1254
|
buildLink: _ref8 => {
|
|
2190
1255
|
var _preload, _ref9;
|
|
2191
|
-
|
|
2192
1256
|
let {
|
|
2193
1257
|
from,
|
|
2194
1258
|
to = '.',
|
|
@@ -2204,11 +1268,12 @@ function createRouter(userOptions) {
|
|
|
2204
1268
|
preloadDelay: userPreloadDelay,
|
|
2205
1269
|
disabled
|
|
2206
1270
|
} = _ref8;
|
|
2207
|
-
|
|
2208
1271
|
// If this link simply reloads the current route,
|
|
2209
1272
|
// make sure it has a new key so it will trigger a data refresh
|
|
1273
|
+
|
|
2210
1274
|
// If this `to` is a valid external URL, return
|
|
2211
1275
|
// null for LinkUtils
|
|
1276
|
+
|
|
2212
1277
|
try {
|
|
2213
1278
|
new URL("" + to);
|
|
2214
1279
|
return {
|
|
@@ -2216,7 +1281,6 @@ function createRouter(userOptions) {
|
|
|
2216
1281
|
href: to
|
|
2217
1282
|
};
|
|
2218
1283
|
} catch (e) {}
|
|
2219
|
-
|
|
2220
1284
|
const nextOpts = {
|
|
2221
1285
|
from,
|
|
2222
1286
|
to,
|
|
@@ -2227,33 +1291,35 @@ function createRouter(userOptions) {
|
|
|
2227
1291
|
};
|
|
2228
1292
|
const next = router.buildNext(nextOpts);
|
|
2229
1293
|
preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
|
|
2230
|
-
const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0;
|
|
1294
|
+
const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0;
|
|
2231
1295
|
|
|
1296
|
+
// Compare path/hash for matches
|
|
2232
1297
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
2233
1298
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
2234
1299
|
const nextPathSplit = next.pathname.split('/');
|
|
2235
1300
|
const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
|
|
2236
|
-
const hashIsEqual = router.state.location.hash === next.hash;
|
|
2237
|
-
|
|
1301
|
+
const hashIsEqual = router.state.location.hash === next.hash;
|
|
1302
|
+
// Combine the matches based on user options
|
|
2238
1303
|
const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
|
|
2239
|
-
const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true;
|
|
1304
|
+
const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true;
|
|
2240
1305
|
|
|
2241
|
-
|
|
1306
|
+
// The final "active" test
|
|
1307
|
+
const isActive = pathTest && hashTest;
|
|
2242
1308
|
|
|
1309
|
+
// The click handler
|
|
2243
1310
|
const handleClick = e => {
|
|
2244
1311
|
if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
|
|
2245
1312
|
e.preventDefault();
|
|
2246
|
-
|
|
2247
1313
|
if (pathIsEqual && !search && !hash) {
|
|
2248
1314
|
router.invalidateRoute(nextOpts);
|
|
2249
|
-
}
|
|
2250
|
-
|
|
1315
|
+
}
|
|
2251
1316
|
|
|
1317
|
+
// All is well? Navigate!)
|
|
2252
1318
|
router.__.navigate(nextOpts);
|
|
2253
1319
|
}
|
|
2254
|
-
};
|
|
2255
|
-
|
|
1320
|
+
};
|
|
2256
1321
|
|
|
1322
|
+
// The click handler
|
|
2257
1323
|
const handleFocus = e => {
|
|
2258
1324
|
if (preload) {
|
|
2259
1325
|
router.preloadRoute(nextOpts, {
|
|
@@ -2262,15 +1328,12 @@ function createRouter(userOptions) {
|
|
|
2262
1328
|
});
|
|
2263
1329
|
}
|
|
2264
1330
|
};
|
|
2265
|
-
|
|
2266
1331
|
const handleEnter = e => {
|
|
2267
1332
|
const target = e.target || {};
|
|
2268
|
-
|
|
2269
1333
|
if (preload) {
|
|
2270
1334
|
if (target.preloadTimeout) {
|
|
2271
1335
|
return;
|
|
2272
1336
|
}
|
|
2273
|
-
|
|
2274
1337
|
target.preloadTimeout = setTimeout(() => {
|
|
2275
1338
|
target.preloadTimeout = null;
|
|
2276
1339
|
router.preloadRoute(nextOpts, {
|
|
@@ -2280,16 +1343,13 @@ function createRouter(userOptions) {
|
|
|
2280
1343
|
}, preloadDelay);
|
|
2281
1344
|
}
|
|
2282
1345
|
};
|
|
2283
|
-
|
|
2284
1346
|
const handleLeave = e => {
|
|
2285
1347
|
const target = e.target || {};
|
|
2286
|
-
|
|
2287
1348
|
if (target.preloadTimeout) {
|
|
2288
1349
|
clearTimeout(target.preloadTimeout);
|
|
2289
1350
|
target.preloadTimeout = null;
|
|
2290
1351
|
}
|
|
2291
1352
|
};
|
|
2292
|
-
|
|
2293
1353
|
return {
|
|
2294
1354
|
type: 'internal',
|
|
2295
1355
|
next,
|
|
@@ -2303,21 +1363,15 @@ function createRouter(userOptions) {
|
|
|
2303
1363
|
},
|
|
2304
1364
|
buildNext: opts => {
|
|
2305
1365
|
const next = router.__.buildLocation(opts);
|
|
2306
|
-
|
|
2307
1366
|
const matches = router.matchRoutes(next.pathname);
|
|
2308
|
-
|
|
2309
1367
|
const __preSearchFilters = matches.map(match => {
|
|
2310
1368
|
var _match$options$preSea;
|
|
2311
|
-
|
|
2312
1369
|
return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
|
|
2313
1370
|
}).flat().filter(Boolean);
|
|
2314
|
-
|
|
2315
1371
|
const __postSearchFilters = matches.map(match => {
|
|
2316
1372
|
var _match$options$postSe;
|
|
2317
|
-
|
|
2318
1373
|
return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
|
|
2319
1374
|
}).flat().filter(Boolean);
|
|
2320
|
-
|
|
2321
1375
|
return router.__.buildLocation(_extends({}, opts, {
|
|
2322
1376
|
__preSearchFilters,
|
|
2323
1377
|
__postSearchFilters
|
|
@@ -2330,12 +1384,10 @@ function createRouter(userOptions) {
|
|
|
2330
1384
|
const routeOptions = routeConfig.options;
|
|
2331
1385
|
const route = createRoute(routeConfig, routeOptions, parent, router);
|
|
2332
1386
|
const existingRoute = router.routesById[route.routeId];
|
|
2333
|
-
|
|
2334
1387
|
if (existingRoute) {
|
|
2335
1388
|
if (process.env.NODE_ENV !== 'production') {
|
|
2336
1389
|
console.warn("Duplicate routes found with id: " + String(route.routeId), router.routesById, route);
|
|
2337
1390
|
}
|
|
2338
|
-
|
|
2339
1391
|
throw new Error();
|
|
2340
1392
|
}
|
|
2341
1393
|
router.routesById[route.routeId] = route;
|
|
@@ -2344,13 +1396,11 @@ function createRouter(userOptions) {
|
|
|
2344
1396
|
return route;
|
|
2345
1397
|
});
|
|
2346
1398
|
};
|
|
2347
|
-
|
|
2348
1399
|
const routes = recurseRoutes([rootRouteConfig]);
|
|
2349
1400
|
return routes[0];
|
|
2350
1401
|
},
|
|
2351
1402
|
parseLocation: (location, previousLocation) => {
|
|
2352
1403
|
var _location$hash$split$;
|
|
2353
|
-
|
|
2354
1404
|
const parsedSearch = router.options.parseSearch(location.search);
|
|
2355
1405
|
return {
|
|
2356
1406
|
pathname: location.pathname,
|
|
@@ -2368,41 +1418,36 @@ function createRouter(userOptions) {
|
|
|
2368
1418
|
},
|
|
2369
1419
|
buildLocation: function buildLocation(dest) {
|
|
2370
1420
|
var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
|
|
2371
|
-
|
|
2372
1421
|
if (dest === void 0) {
|
|
2373
1422
|
dest = {};
|
|
2374
1423
|
}
|
|
2375
|
-
|
|
2376
1424
|
// const resolvedFrom: Location = {
|
|
2377
1425
|
// ...router.location,
|
|
2378
1426
|
const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
|
|
2379
|
-
|
|
2380
1427
|
let pathname = resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
|
|
2381
|
-
|
|
2382
1428
|
const fromMatches = router.matchRoutes(router.location.pathname, {
|
|
2383
1429
|
strictParseParams: true
|
|
2384
1430
|
});
|
|
2385
1431
|
const toMatches = router.matchRoutes(pathname);
|
|
2386
|
-
|
|
2387
1432
|
const prevParams = _extends({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
|
|
2388
|
-
|
|
2389
1433
|
let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
|
|
2390
|
-
|
|
2391
1434
|
if (nextParams) {
|
|
2392
1435
|
toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
|
|
2393
1436
|
Object.assign({}, nextParams, fn(nextParams));
|
|
2394
1437
|
});
|
|
2395
1438
|
}
|
|
1439
|
+
pathname = interpolatePath(pathname, nextParams != null ? nextParams : {});
|
|
2396
1440
|
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
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
|
|
1441
|
+
// Pre filters first
|
|
1442
|
+
const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.location.search) : router.location.search;
|
|
2400
1443
|
|
|
1444
|
+
// Then the link/navigate function
|
|
2401
1445
|
const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
|
|
2402
1446
|
: dest.search ? (_functionalUpdate = functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
|
|
2403
1447
|
: (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
|
|
2404
|
-
: {};
|
|
1448
|
+
: {};
|
|
2405
1449
|
|
|
1450
|
+
// Then post filters
|
|
2406
1451
|
const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
|
|
2407
1452
|
const search = replaceEqualDeep(router.location.search, postFilteredSearch);
|
|
2408
1453
|
const searchStr = router.options.stringifySearch(search);
|
|
@@ -2422,17 +1467,13 @@ function createRouter(userOptions) {
|
|
|
2422
1467
|
const id = '' + Date.now() + Math.random();
|
|
2423
1468
|
if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
|
|
2424
1469
|
let nextAction = 'replace';
|
|
2425
|
-
|
|
2426
1470
|
if (!replace) {
|
|
2427
1471
|
nextAction = 'push';
|
|
2428
1472
|
}
|
|
2429
|
-
|
|
2430
1473
|
const isSameUrl = router.__.parseLocation(history.location).href === next.href;
|
|
2431
|
-
|
|
2432
1474
|
if (isSameUrl && !next.key) {
|
|
2433
1475
|
nextAction = 'replace';
|
|
2434
1476
|
}
|
|
2435
|
-
|
|
2436
1477
|
if (nextAction === 'replace') {
|
|
2437
1478
|
history.replace({
|
|
2438
1479
|
pathname: next.pathname,
|
|
@@ -2450,38 +1491,35 @@ function createRouter(userOptions) {
|
|
|
2450
1491
|
id
|
|
2451
1492
|
});
|
|
2452
1493
|
}
|
|
2453
|
-
|
|
2454
1494
|
router.navigationPromise = new Promise(resolve => {
|
|
2455
1495
|
const previousNavigationResolve = router.resolveNavigation;
|
|
2456
|
-
|
|
2457
1496
|
router.resolveNavigation = () => {
|
|
2458
1497
|
previousNavigationResolve();
|
|
2459
1498
|
resolve();
|
|
1499
|
+
delete router.navigationPromise;
|
|
2460
1500
|
};
|
|
2461
1501
|
});
|
|
2462
1502
|
return router.navigationPromise;
|
|
2463
1503
|
}
|
|
2464
1504
|
}
|
|
2465
1505
|
};
|
|
2466
|
-
router.update(userOptions);
|
|
1506
|
+
router.update(userOptions);
|
|
2467
1507
|
|
|
1508
|
+
// Allow frameworks to hook into the router creation
|
|
2468
1509
|
router.options.createRouter == null ? void 0 : router.options.createRouter(router);
|
|
2469
1510
|
return router;
|
|
2470
1511
|
}
|
|
2471
|
-
|
|
2472
1512
|
function isCtrlEvent(e) {
|
|
2473
1513
|
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
2474
1514
|
}
|
|
2475
|
-
|
|
2476
1515
|
function cascadeLoaderData(matches) {
|
|
2477
1516
|
matches.forEach((match, index) => {
|
|
2478
1517
|
const parent = matches[index - 1];
|
|
2479
|
-
|
|
2480
1518
|
if (parent) {
|
|
2481
1519
|
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
2482
1520
|
}
|
|
2483
1521
|
});
|
|
2484
1522
|
}
|
|
2485
1523
|
|
|
2486
|
-
export { cleanPath,
|
|
1524
|
+
export { cleanPath, createRoute, createRouteConfig, createRouteMatch, createRouter, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, joinPaths, last, matchByPath, matchPathname, parsePathname, parseSearchWith, pick, replaceEqualDeep, resolvePath, rootRouteId, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, warning };
|
|
2487
1525
|
//# sourceMappingURL=index.js.map
|