@tanstack/router-core 0.0.1-beta.1 → 0.0.1-beta.10
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/packages/router-core/src/index.js +1 -1
- package/build/cjs/packages/router-core/src/qss.js +1 -0
- package/build/cjs/packages/router-core/src/qss.js.map +1 -1
- package/build/cjs/packages/router-core/src/route.js +9 -23
- package/build/cjs/packages/router-core/src/route.js.map +1 -1
- package/build/cjs/packages/router-core/src/routeMatch.js +24 -27
- package/build/cjs/packages/router-core/src/routeMatch.js.map +1 -1
- package/build/cjs/packages/router-core/src/router.js +109 -72
- package/build/cjs/packages/router-core/src/router.js.map +1 -1
- package/build/cjs/packages/router-core/src/utils.js +7 -0
- package/build/cjs/packages/router-core/src/utils.js.map +1 -1
- package/build/esm/index.js +147 -118
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +138 -144
- package/build/types/index.d.ts +85 -80
- package/build/umd/index.development.js +147 -118
- 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 +1 -1
- package/src/qss.ts +1 -0
- package/src/route.ts +10 -26
- package/src/routeMatch.ts +29 -33
- package/src/router.ts +144 -66
- package/src/utils.ts +7 -0
package/build/esm/index.js
CHANGED
|
@@ -930,6 +930,12 @@ function functionalUpdate(updater, previous) {
|
|
|
930
930
|
|
|
931
931
|
return updater;
|
|
932
932
|
}
|
|
933
|
+
function pick(parent, keys) {
|
|
934
|
+
return keys.reduce((obj, key) => {
|
|
935
|
+
obj[key] = parent[key];
|
|
936
|
+
return obj;
|
|
937
|
+
}, {});
|
|
938
|
+
}
|
|
933
939
|
|
|
934
940
|
function joinPaths(paths) {
|
|
935
941
|
return cleanPath(paths.filter(Boolean).join('/'));
|
|
@@ -1156,6 +1162,7 @@ function toValue(mix) {
|
|
|
1156
1162
|
var str = decodeURIComponent(mix);
|
|
1157
1163
|
if (str === 'false') return false;
|
|
1158
1164
|
if (str === 'true') return true;
|
|
1165
|
+
if (str.charAt(0) === '0') return str;
|
|
1159
1166
|
return +str * 0 === 0 ? +str : str;
|
|
1160
1167
|
}
|
|
1161
1168
|
|
|
@@ -1206,7 +1213,7 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1206
1213
|
|
|
1207
1214
|
const action = router.state.actions[id] || (() => {
|
|
1208
1215
|
router.state.actions[id] = {
|
|
1209
|
-
|
|
1216
|
+
submissions: [],
|
|
1210
1217
|
submit: async (submission, actionOpts) => {
|
|
1211
1218
|
var _actionOpts$invalidat;
|
|
1212
1219
|
|
|
@@ -1215,18 +1222,20 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1215
1222
|
}
|
|
1216
1223
|
|
|
1217
1224
|
const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
|
|
1225
|
+
|
|
1226
|
+
if (!(actionOpts != null && actionOpts.multi)) {
|
|
1227
|
+
action.submissions = action.submissions.filter(d => d.isMulti);
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1218
1230
|
const actionState = {
|
|
1219
1231
|
submittedAt: Date.now(),
|
|
1220
1232
|
status: 'pending',
|
|
1221
|
-
submission
|
|
1233
|
+
submission,
|
|
1234
|
+
isMulti: !!(actionOpts != null && actionOpts.multi)
|
|
1222
1235
|
};
|
|
1223
1236
|
action.current = actionState;
|
|
1224
1237
|
action.latest = actionState;
|
|
1225
|
-
action.
|
|
1226
|
-
router.state = _extends({}, router.state, {
|
|
1227
|
-
currentAction: actionState,
|
|
1228
|
-
latestAction: actionState
|
|
1229
|
-
});
|
|
1238
|
+
action.submissions.push(actionState);
|
|
1230
1239
|
router.notify();
|
|
1231
1240
|
|
|
1232
1241
|
try {
|
|
@@ -1248,11 +1257,6 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1248
1257
|
actionState.error = err;
|
|
1249
1258
|
actionState.status = 'error';
|
|
1250
1259
|
} finally {
|
|
1251
|
-
action.pending = action.pending.filter(d => d !== actionState);
|
|
1252
|
-
router.removeActionQueue.push({
|
|
1253
|
-
action,
|
|
1254
|
-
actionState
|
|
1255
|
-
});
|
|
1256
1260
|
router.notify();
|
|
1257
1261
|
}
|
|
1258
1262
|
}
|
|
@@ -1327,15 +1331,6 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1327
1331
|
});
|
|
1328
1332
|
return route;
|
|
1329
1333
|
}
|
|
1330
|
-
function cascadeLoaderData(matches) {
|
|
1331
|
-
matches.forEach((match, index) => {
|
|
1332
|
-
const parent = matches[index - 1];
|
|
1333
|
-
|
|
1334
|
-
if (parent) {
|
|
1335
|
-
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
1336
|
-
}
|
|
1337
|
-
});
|
|
1338
|
-
}
|
|
1339
1334
|
|
|
1340
1335
|
const rootRouteId = '__root__';
|
|
1341
1336
|
const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
|
|
@@ -1401,6 +1396,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1401
1396
|
isFetching: false,
|
|
1402
1397
|
isInvalid: false,
|
|
1403
1398
|
invalidAt: Infinity,
|
|
1399
|
+
// pendingActions: [],
|
|
1404
1400
|
getIsInvalid: () => {
|
|
1405
1401
|
const now = Date.now();
|
|
1406
1402
|
return routeMatch.isInvalid || routeMatch.invalidAt < now;
|
|
@@ -1440,17 +1436,6 @@ function createRouteMatch(router, route, opts) {
|
|
|
1440
1436
|
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
1441
1437
|
delete routeMatch.__.pendingMinPromise;
|
|
1442
1438
|
},
|
|
1443
|
-
// setParentMatch: (parentMatch?: RouteMatch) => {
|
|
1444
|
-
// routeMatch.parentMatch = parentMatch
|
|
1445
|
-
// },
|
|
1446
|
-
// addChildMatch: (childMatch: RouteMatch) => {
|
|
1447
|
-
// if (
|
|
1448
|
-
// routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
|
|
1449
|
-
// ) {
|
|
1450
|
-
// return
|
|
1451
|
-
// }
|
|
1452
|
-
// routeMatch.childMatches.push(childMatch)
|
|
1453
|
-
// },
|
|
1454
1439
|
validate: () => {
|
|
1455
1440
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1456
1441
|
|
|
@@ -1458,9 +1443,11 @@ function createRouteMatch(router, route, opts) {
|
|
|
1458
1443
|
const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
|
|
1459
1444
|
|
|
1460
1445
|
try {
|
|
1446
|
+
var _validator;
|
|
1447
|
+
|
|
1461
1448
|
const prevSearch = routeMatch.routeSearch;
|
|
1462
1449
|
const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
|
|
1463
|
-
let nextSearch = replaceEqualDeep(prevSearch, validator == null ? void 0 : validator(parentSearch)); // Invalidate route matches when search param stability changes
|
|
1450
|
+
let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {}); // Invalidate route matches when search param stability changes
|
|
1464
1451
|
|
|
1465
1452
|
if (prevSearch !== nextSearch) {
|
|
1466
1453
|
routeMatch.isInvalid = true;
|
|
@@ -1468,6 +1455,13 @@ function createRouteMatch(router, route, opts) {
|
|
|
1468
1455
|
|
|
1469
1456
|
routeMatch.routeSearch = nextSearch;
|
|
1470
1457
|
routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
|
|
1458
|
+
elementTypes.map(async type => {
|
|
1459
|
+
const routeElement = routeMatch.options[type];
|
|
1460
|
+
|
|
1461
|
+
if (typeof routeMatch.__[type] !== 'function') {
|
|
1462
|
+
routeMatch.__[type] = routeElement;
|
|
1463
|
+
}
|
|
1464
|
+
});
|
|
1471
1465
|
} catch (err) {
|
|
1472
1466
|
console.error(err);
|
|
1473
1467
|
const error = new Error('Invalid search params found', {
|
|
@@ -1513,7 +1507,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1513
1507
|
|
|
1514
1508
|
if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
|
|
1515
1509
|
const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
|
|
1516
|
-
routeMatch.fetch({
|
|
1510
|
+
await routeMatch.fetch({
|
|
1517
1511
|
maxAge
|
|
1518
1512
|
});
|
|
1519
1513
|
}
|
|
@@ -1536,7 +1530,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1536
1530
|
routeMatch.isFetching = true;
|
|
1537
1531
|
routeMatch.__.resolve = resolve;
|
|
1538
1532
|
|
|
1539
|
-
|
|
1533
|
+
routeMatch.__.loaderDataPromise = (async () => {
|
|
1540
1534
|
// Load the elements and data in parallel
|
|
1541
1535
|
routeMatch.__.elementsPromise = (async () => {
|
|
1542
1536
|
// then run all element and data loaders in parallel
|
|
@@ -1544,11 +1538,9 @@ function createRouteMatch(router, route, opts) {
|
|
|
1544
1538
|
await Promise.all(elementTypes.map(async type => {
|
|
1545
1539
|
const routeElement = routeMatch.options[type];
|
|
1546
1540
|
|
|
1547
|
-
if (routeMatch.__[type]) {
|
|
1548
|
-
|
|
1541
|
+
if (typeof routeMatch.__[type] === 'function') {
|
|
1542
|
+
routeMatch.__[type] = await router.options.createElement(routeElement);
|
|
1549
1543
|
}
|
|
1550
|
-
|
|
1551
|
-
routeMatch.__[type] = await router.options.createElement(routeElement);
|
|
1552
1544
|
}));
|
|
1553
1545
|
})();
|
|
1554
1546
|
|
|
@@ -1564,7 +1556,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1564
1556
|
});
|
|
1565
1557
|
|
|
1566
1558
|
if (id !== routeMatch.__.latestId) {
|
|
1567
|
-
return routeMatch.__.
|
|
1559
|
+
return routeMatch.__.loadPromise;
|
|
1568
1560
|
}
|
|
1569
1561
|
|
|
1570
1562
|
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
@@ -1576,7 +1568,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1576
1568
|
routeMatch.invalidAt = routeMatch.updatedAt + ((_ref = (_ref2 = (_opts$maxAge = opts == null ? void 0 : opts.maxAge) != null ? _opts$maxAge : routeMatch.options.loaderMaxAge) != null ? _ref2 : router.options.defaultLoaderMaxAge) != null ? _ref : 0);
|
|
1577
1569
|
} catch (err) {
|
|
1578
1570
|
if (id !== routeMatch.__.latestId) {
|
|
1579
|
-
return routeMatch.__.
|
|
1571
|
+
return routeMatch.__.loadPromise;
|
|
1580
1572
|
}
|
|
1581
1573
|
|
|
1582
1574
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -1593,7 +1585,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1593
1585
|
await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
|
|
1594
1586
|
|
|
1595
1587
|
if (id !== routeMatch.__.latestId) {
|
|
1596
|
-
return routeMatch.__.
|
|
1588
|
+
return routeMatch.__.loadPromise;
|
|
1597
1589
|
}
|
|
1598
1590
|
|
|
1599
1591
|
if (routeMatch.__.pendingMinPromise) {
|
|
@@ -1602,7 +1594,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1602
1594
|
}
|
|
1603
1595
|
} finally {
|
|
1604
1596
|
if (id !== routeMatch.__.latestId) {
|
|
1605
|
-
return routeMatch.__.
|
|
1597
|
+
return routeMatch.__.loadPromise;
|
|
1606
1598
|
}
|
|
1607
1599
|
|
|
1608
1600
|
routeMatch.__.cancelPending();
|
|
@@ -1614,16 +1606,16 @@ function createRouteMatch(router, route, opts) {
|
|
|
1614
1606
|
}
|
|
1615
1607
|
})();
|
|
1616
1608
|
|
|
1617
|
-
routeMatch.__.
|
|
1618
|
-
await loaderPromise;
|
|
1609
|
+
await routeMatch.__.loaderDataPromise;
|
|
1619
1610
|
|
|
1620
1611
|
if (id !== routeMatch.__.latestId) {
|
|
1621
|
-
return routeMatch.__.
|
|
1612
|
+
return routeMatch.__.loadPromise;
|
|
1622
1613
|
}
|
|
1623
1614
|
|
|
1624
|
-
delete routeMatch.__.
|
|
1615
|
+
delete routeMatch.__.loaderDataPromise;
|
|
1625
1616
|
});
|
|
1626
|
-
|
|
1617
|
+
await routeMatch.__.loadPromise;
|
|
1618
|
+
delete routeMatch.__.loadPromise;
|
|
1627
1619
|
}
|
|
1628
1620
|
});
|
|
1629
1621
|
|
|
@@ -1684,9 +1676,22 @@ function stringifySearchWith(stringify) {
|
|
|
1684
1676
|
|
|
1685
1677
|
var _window$document;
|
|
1686
1678
|
// Detect if we're in the DOM
|
|
1687
|
-
const isServer =
|
|
1679
|
+
const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement); // This is the default history object if none is defined
|
|
1688
1680
|
|
|
1689
|
-
const createDefaultHistory = () =>
|
|
1681
|
+
const createDefaultHistory = () => isServer ? createMemoryHistory() : createBrowserHistory();
|
|
1682
|
+
|
|
1683
|
+
function getInitialRouterState() {
|
|
1684
|
+
return {
|
|
1685
|
+
status: 'idle',
|
|
1686
|
+
location: null,
|
|
1687
|
+
matches: [],
|
|
1688
|
+
actions: {},
|
|
1689
|
+
loaders: {},
|
|
1690
|
+
lastUpdated: Date.now(),
|
|
1691
|
+
isFetching: false,
|
|
1692
|
+
isPreloading: false
|
|
1693
|
+
};
|
|
1694
|
+
}
|
|
1690
1695
|
|
|
1691
1696
|
function createRouter(userOptions) {
|
|
1692
1697
|
var _userOptions$stringif, _userOptions$parseSea;
|
|
@@ -1707,7 +1712,6 @@ function createRouter(userOptions) {
|
|
|
1707
1712
|
history,
|
|
1708
1713
|
options: originalOptions,
|
|
1709
1714
|
listeners: [],
|
|
1710
|
-
removeActionQueue: [],
|
|
1711
1715
|
// Resolved after construction
|
|
1712
1716
|
basepath: '',
|
|
1713
1717
|
routeTree: undefined,
|
|
@@ -1718,16 +1722,10 @@ function createRouter(userOptions) {
|
|
|
1718
1722
|
navigationPromise: Promise.resolve(),
|
|
1719
1723
|
resolveNavigation: () => {},
|
|
1720
1724
|
matchCache: {},
|
|
1721
|
-
state:
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
actions: {},
|
|
1726
|
-
loaders: {},
|
|
1727
|
-
loaderData: {},
|
|
1728
|
-
lastUpdated: Date.now(),
|
|
1729
|
-
isFetching: false,
|
|
1730
|
-
isPreloading: false
|
|
1725
|
+
state: getInitialRouterState(),
|
|
1726
|
+
reset: () => {
|
|
1727
|
+
router.state = getInitialRouterState();
|
|
1728
|
+
router.notify();
|
|
1731
1729
|
},
|
|
1732
1730
|
startedLoadingAt: Date.now(),
|
|
1733
1731
|
subscribe: listener => {
|
|
@@ -1745,7 +1743,27 @@ function createRouter(userOptions) {
|
|
|
1745
1743
|
isPreloading: Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId))
|
|
1746
1744
|
});
|
|
1747
1745
|
cascadeLoaderData(router.state.matches);
|
|
1748
|
-
router.listeners.forEach(listener => listener());
|
|
1746
|
+
router.listeners.forEach(listener => listener(router));
|
|
1747
|
+
},
|
|
1748
|
+
dehydrateState: () => {
|
|
1749
|
+
return _extends({}, pick(router.state, ['status', 'location', 'lastUpdated']), {
|
|
1750
|
+
matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
|
|
1751
|
+
});
|
|
1752
|
+
},
|
|
1753
|
+
hydrateState: dehydratedState => {
|
|
1754
|
+
// Match the routes
|
|
1755
|
+
const matches = router.matchRoutes(router.location.pathname, {
|
|
1756
|
+
strictParseParams: true
|
|
1757
|
+
});
|
|
1758
|
+
matches.forEach((match, index) => {
|
|
1759
|
+
const dehydratedMatch = dehydratedState.matches[index];
|
|
1760
|
+
invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
|
|
1761
|
+
Object.assign(match, dehydratedMatch);
|
|
1762
|
+
});
|
|
1763
|
+
router.loadMatches(matches);
|
|
1764
|
+
router.state = _extends({}, router.state, dehydratedState, {
|
|
1765
|
+
matches
|
|
1766
|
+
});
|
|
1749
1767
|
},
|
|
1750
1768
|
mount: () => {
|
|
1751
1769
|
const next = router.__.buildLocation({
|
|
@@ -1758,12 +1776,11 @@ function createRouter(userOptions) {
|
|
|
1758
1776
|
|
|
1759
1777
|
if (next.href !== router.location.href) {
|
|
1760
1778
|
router.__.commitLocation(next, true);
|
|
1761
|
-
}
|
|
1762
|
-
router.loadLocation();
|
|
1763
|
-
}
|
|
1779
|
+
} // router.load()
|
|
1764
1780
|
|
|
1765
|
-
|
|
1766
|
-
|
|
1781
|
+
|
|
1782
|
+
const unsub = router.history.listen(event => {
|
|
1783
|
+
router.load(router.__.parseLocation(event.location, router.location));
|
|
1767
1784
|
}); // addEventListener does not exist in React Native, but window does
|
|
1768
1785
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1769
1786
|
|
|
@@ -1774,16 +1791,30 @@ function createRouter(userOptions) {
|
|
|
1774
1791
|
}
|
|
1775
1792
|
|
|
1776
1793
|
return () => {
|
|
1777
|
-
unsub();
|
|
1794
|
+
unsub();
|
|
1778
1795
|
|
|
1779
|
-
window.removeEventListener
|
|
1780
|
-
|
|
1796
|
+
if (!isServer && window.removeEventListener) {
|
|
1797
|
+
// Be sure to unsubscribe if a new handler is set
|
|
1798
|
+
window.removeEventListener('visibilitychange', router.onFocus);
|
|
1799
|
+
window.removeEventListener('focus', router.onFocus);
|
|
1800
|
+
}
|
|
1781
1801
|
};
|
|
1782
1802
|
},
|
|
1783
1803
|
onFocus: () => {
|
|
1784
|
-
router.
|
|
1804
|
+
router.load();
|
|
1785
1805
|
},
|
|
1786
1806
|
update: opts => {
|
|
1807
|
+
const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
|
|
1808
|
+
|
|
1809
|
+
if (!router.location || newHistory) {
|
|
1810
|
+
if (opts != null && opts.history) {
|
|
1811
|
+
router.history = opts.history;
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
router.location = router.__.parseLocation(router.history.location);
|
|
1815
|
+
router.state.location = router.location;
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1787
1818
|
Object.assign(router.options, opts);
|
|
1788
1819
|
const {
|
|
1789
1820
|
basepath,
|
|
@@ -1804,35 +1835,19 @@ function createRouter(userOptions) {
|
|
|
1804
1835
|
match.cancel();
|
|
1805
1836
|
});
|
|
1806
1837
|
},
|
|
1807
|
-
|
|
1838
|
+
load: async next => {
|
|
1808
1839
|
const id = Math.random();
|
|
1809
1840
|
router.startedLoadingAt = id;
|
|
1810
1841
|
|
|
1811
1842
|
if (next) {
|
|
1812
1843
|
// Ingest the new location
|
|
1813
1844
|
router.location = next;
|
|
1814
|
-
} //
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
router.removeActionQueue.forEach(_ref => {
|
|
1818
|
-
let {
|
|
1819
|
-
action,
|
|
1820
|
-
actionState
|
|
1821
|
-
} = _ref;
|
|
1845
|
+
} // Cancel any pending matches
|
|
1822
1846
|
|
|
1823
|
-
if (router.state.currentAction === actionState) {
|
|
1824
|
-
router.state.currentAction = undefined;
|
|
1825
|
-
}
|
|
1826
|
-
|
|
1827
|
-
if (action.current === actionState) {
|
|
1828
|
-
action.current = undefined;
|
|
1829
|
-
}
|
|
1830
|
-
});
|
|
1831
|
-
router.removeActionQueue = []; // Cancel any pending matches
|
|
1832
1847
|
|
|
1833
1848
|
router.cancelMatches(); // Match the routes
|
|
1834
1849
|
|
|
1835
|
-
const matches = router.matchRoutes(location.pathname, {
|
|
1850
|
+
const matches = router.matchRoutes(router.location.pathname, {
|
|
1836
1851
|
strictParseParams: true
|
|
1837
1852
|
});
|
|
1838
1853
|
router.state = _extends({}, router.state, {
|
|
@@ -1865,19 +1880,24 @@ function createRouter(userOptions) {
|
|
|
1865
1880
|
});
|
|
1866
1881
|
const now = Date.now();
|
|
1867
1882
|
exiting.forEach(d => {
|
|
1868
|
-
var
|
|
1883
|
+
var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
|
|
1869
1884
|
|
|
1870
1885
|
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
1871
1886
|
params: d.params,
|
|
1872
1887
|
search: d.routeSearch
|
|
1873
|
-
}); // Clear
|
|
1888
|
+
}); // // Clear actions
|
|
1889
|
+
// if (d.action) {
|
|
1890
|
+
// d.action.current = undefined
|
|
1891
|
+
// d.action.submissions = []
|
|
1892
|
+
// }
|
|
1893
|
+
// Clear idle error states when match leaves
|
|
1874
1894
|
|
|
1875
1895
|
if (d.status === 'error' && !d.isFetching) {
|
|
1876
1896
|
d.status = 'idle';
|
|
1877
1897
|
d.error = undefined;
|
|
1878
1898
|
}
|
|
1879
1899
|
|
|
1880
|
-
const gc = Math.max((
|
|
1900
|
+
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
1901
|
|
|
1882
1902
|
if (gc > 0) {
|
|
1883
1903
|
router.matchCache[d.matchId] = {
|
|
@@ -1901,18 +1921,20 @@ function createRouter(userOptions) {
|
|
|
1901
1921
|
search: d.search
|
|
1902
1922
|
});
|
|
1903
1923
|
delete router.matchCache[d.matchId];
|
|
1904
|
-
});
|
|
1905
|
-
|
|
1906
|
-
if (matches.some(d => d.status === 'loading')) {
|
|
1907
|
-
router.notify();
|
|
1908
|
-
await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
|
|
1909
|
-
}
|
|
1924
|
+
}); // router.notify()
|
|
1910
1925
|
|
|
1911
1926
|
if (router.startedLoadingAt !== id) {
|
|
1912
1927
|
// Ignore side-effects of match loading
|
|
1913
1928
|
return;
|
|
1914
1929
|
}
|
|
1915
1930
|
|
|
1931
|
+
matches.forEach(match => {
|
|
1932
|
+
// Clear actions
|
|
1933
|
+
if (match.action) {
|
|
1934
|
+
match.action.current = undefined;
|
|
1935
|
+
match.action.submissions = [];
|
|
1936
|
+
}
|
|
1937
|
+
});
|
|
1916
1938
|
router.state = _extends({}, router.state, {
|
|
1917
1939
|
location: router.location,
|
|
1918
1940
|
matches,
|
|
@@ -1953,7 +1975,7 @@ function createRouter(userOptions) {
|
|
|
1953
1975
|
return matches;
|
|
1954
1976
|
},
|
|
1955
1977
|
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
1956
|
-
var
|
|
1978
|
+
var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
|
|
1957
1979
|
|
|
1958
1980
|
if (navigateOpts === void 0) {
|
|
1959
1981
|
navigateOpts = router.location;
|
|
@@ -1965,8 +1987,8 @@ function createRouter(userOptions) {
|
|
|
1965
1987
|
});
|
|
1966
1988
|
await router.loadMatches(matches, {
|
|
1967
1989
|
preload: true,
|
|
1968
|
-
maxAge: (
|
|
1969
|
-
gcMaxAge: (
|
|
1990
|
+
maxAge: (_ref3 = (_ref4 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref4 : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0,
|
|
1991
|
+
gcMaxAge: (_ref5 = (_ref6 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref6 : router.options.defaultLoaderGcMaxAge) != null ? _ref5 : 0
|
|
1970
1992
|
});
|
|
1971
1993
|
return matches;
|
|
1972
1994
|
},
|
|
@@ -2068,9 +2090,12 @@ function createRouter(userOptions) {
|
|
|
2068
2090
|
|
|
2069
2091
|
if (match.status === 'loading') {
|
|
2070
2092
|
// If requested, start the pending timers
|
|
2071
|
-
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
|
|
2072
|
-
|
|
2093
|
+
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
|
|
2094
|
+
}
|
|
2073
2095
|
|
|
2096
|
+
if (match.__.loadPromise) {
|
|
2097
|
+
// Wait for the first sign of activity from the match
|
|
2098
|
+
// This might be completion, error, or a pending state
|
|
2074
2099
|
await match.__.loadPromise;
|
|
2075
2100
|
}
|
|
2076
2101
|
});
|
|
@@ -2121,7 +2146,7 @@ function createRouter(userOptions) {
|
|
|
2121
2146
|
to: next.pathname
|
|
2122
2147
|
}));
|
|
2123
2148
|
},
|
|
2124
|
-
navigate: async
|
|
2149
|
+
navigate: async _ref7 => {
|
|
2125
2150
|
let {
|
|
2126
2151
|
from,
|
|
2127
2152
|
to = '.',
|
|
@@ -2129,7 +2154,7 @@ function createRouter(userOptions) {
|
|
|
2129
2154
|
hash,
|
|
2130
2155
|
replace,
|
|
2131
2156
|
params
|
|
2132
|
-
} =
|
|
2157
|
+
} = _ref7;
|
|
2133
2158
|
// If this link simply reloads the current route,
|
|
2134
2159
|
// make sure it has a new key so it will trigger a data refresh
|
|
2135
2160
|
// If this `to` is a valid external URL, return
|
|
@@ -2153,8 +2178,8 @@ function createRouter(userOptions) {
|
|
|
2153
2178
|
params
|
|
2154
2179
|
});
|
|
2155
2180
|
},
|
|
2156
|
-
buildLink:
|
|
2157
|
-
var _preload,
|
|
2181
|
+
buildLink: _ref8 => {
|
|
2182
|
+
var _preload, _ref9;
|
|
2158
2183
|
|
|
2159
2184
|
let {
|
|
2160
2185
|
from,
|
|
@@ -2170,7 +2195,7 @@ function createRouter(userOptions) {
|
|
|
2170
2195
|
preloadGcMaxAge: userPreloadGcMaxAge,
|
|
2171
2196
|
preloadDelay: userPreloadDelay,
|
|
2172
2197
|
disabled
|
|
2173
|
-
} =
|
|
2198
|
+
} = _ref8;
|
|
2174
2199
|
|
|
2175
2200
|
// If this link simply reloads the current route,
|
|
2176
2201
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -2194,7 +2219,7 @@ function createRouter(userOptions) {
|
|
|
2194
2219
|
};
|
|
2195
2220
|
const next = router.buildNext(nextOpts);
|
|
2196
2221
|
preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
|
|
2197
|
-
const preloadDelay = (
|
|
2222
|
+
const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0; // Compare path/hash for matches
|
|
2198
2223
|
|
|
2199
2224
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
2200
2225
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
@@ -2295,11 +2320,7 @@ function createRouter(userOptions) {
|
|
|
2295
2320
|
const recurseRoutes = (routeConfigs, parent) => {
|
|
2296
2321
|
return routeConfigs.map(routeConfig => {
|
|
2297
2322
|
const routeOptions = routeConfig.options;
|
|
2298
|
-
const route = createRoute(routeConfig, routeOptions, parent, router);
|
|
2299
|
-
// pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
|
|
2300
|
-
// pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
|
|
2301
|
-
// }
|
|
2302
|
-
|
|
2323
|
+
const route = createRoute(routeConfig, routeOptions, parent, router);
|
|
2303
2324
|
const existingRoute = router.routesById[route.routeId];
|
|
2304
2325
|
|
|
2305
2326
|
if (existingRoute) {
|
|
@@ -2434,8 +2455,6 @@ function createRouter(userOptions) {
|
|
|
2434
2455
|
}
|
|
2435
2456
|
}
|
|
2436
2457
|
};
|
|
2437
|
-
router.location = router.__.parseLocation(history.location);
|
|
2438
|
-
router.state.location = router.location;
|
|
2439
2458
|
router.update(userOptions); // Allow frameworks to hook into the router creation
|
|
2440
2459
|
|
|
2441
2460
|
router.options.createRouter == null ? void 0 : router.options.createRouter(router);
|
|
@@ -2446,5 +2465,15 @@ function isCtrlEvent(e) {
|
|
|
2446
2465
|
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
2447
2466
|
}
|
|
2448
2467
|
|
|
2449
|
-
|
|
2468
|
+
function cascadeLoaderData(matches) {
|
|
2469
|
+
matches.forEach((match, index) => {
|
|
2470
|
+
const parent = matches[index - 1];
|
|
2471
|
+
|
|
2472
|
+
if (parent) {
|
|
2473
|
+
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
2474
|
+
}
|
|
2475
|
+
});
|
|
2476
|
+
}
|
|
2477
|
+
|
|
2478
|
+
export { cleanPath, createBrowserHistory, createHashHistory, createMemoryHistory, createRoute, createRouteConfig, createRouteMatch, createRouter, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, invariant, joinPaths, last, matchByPath, matchPathname, parsePathname, parseSearchWith, pick, replaceEqualDeep, resolvePath, rootRouteId, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, warning };
|
|
2450
2479
|
//# sourceMappingURL=index.js.map
|