@tanstack/react-router 0.0.1-alpha.4 → 0.0.1-alpha.6
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/react-router/src/index.js +12 -12
- package/build/cjs/react-router/src/index.js.map +1 -1
- package/build/cjs/router-core/build/esm/index.js +66 -47
- package/build/cjs/router-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +79 -56
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +29 -29
- package/build/types/index.d.ts +1 -5
- package/build/umd/index.development.js +78 -59
- 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/index.tsx +13 -13
package/build/esm/index.js
CHANGED
|
@@ -1013,6 +1013,7 @@ function createRouter(userOptions) {
|
|
|
1013
1013
|
let router = {
|
|
1014
1014
|
options: originalOptions,
|
|
1015
1015
|
listeners: [],
|
|
1016
|
+
removeActionQueue: [],
|
|
1016
1017
|
// Resolved after construction
|
|
1017
1018
|
basepath: '',
|
|
1018
1019
|
routeTree: undefined,
|
|
@@ -1136,12 +1137,14 @@ function createRouter(userOptions) {
|
|
|
1136
1137
|
strictParseParams: true
|
|
1137
1138
|
});
|
|
1138
1139
|
const toMatches = router.matchRoutes(pathname);
|
|
1139
|
-
|
|
1140
|
+
|
|
1141
|
+
const prevParams = _extends$1({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
|
|
1142
|
+
|
|
1140
1143
|
let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
|
|
1141
1144
|
|
|
1142
1145
|
if (nextParams) {
|
|
1143
1146
|
toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
|
|
1144
|
-
Object.assign(nextParams, fn(nextParams));
|
|
1147
|
+
Object.assign({}, nextParams, fn(nextParams));
|
|
1145
1148
|
});
|
|
1146
1149
|
}
|
|
1147
1150
|
|
|
@@ -1246,20 +1249,30 @@ function createRouter(userOptions) {
|
|
|
1246
1249
|
if (next) {
|
|
1247
1250
|
// Ingest the new location
|
|
1248
1251
|
router.location = next;
|
|
1249
|
-
} //
|
|
1252
|
+
} // Clear out old actions
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
router.removeActionQueue.forEach(_ref => {
|
|
1256
|
+
let {
|
|
1257
|
+
action,
|
|
1258
|
+
actionState
|
|
1259
|
+
} = _ref;
|
|
1260
|
+
|
|
1261
|
+
if (router.state.currentAction === actionState) {
|
|
1262
|
+
router.state.currentAction = undefined;
|
|
1263
|
+
}
|
|
1250
1264
|
|
|
1265
|
+
if (action.current === actionState) {
|
|
1266
|
+
action.current = undefined;
|
|
1267
|
+
}
|
|
1268
|
+
});
|
|
1269
|
+
router.removeActionQueue = []; // Cancel any pending matches
|
|
1251
1270
|
|
|
1252
1271
|
router.cancelMatches(); // Match the routes
|
|
1253
1272
|
|
|
1254
1273
|
const unloadedMatches = router.matchRoutes(location.pathname, {
|
|
1255
1274
|
strictParseParams: true
|
|
1256
1275
|
});
|
|
1257
|
-
unloadedMatches.forEach((match, index) => {
|
|
1258
|
-
const parent = unloadedMatches[index - 1];
|
|
1259
|
-
const child = unloadedMatches[index + 1];
|
|
1260
|
-
if (parent) match.__.setParentMatch(parent);
|
|
1261
|
-
if (child) match.__.addChildMatch(child);
|
|
1262
|
-
});
|
|
1263
1276
|
router.state = _extends$1({}, router.state, {
|
|
1264
1277
|
pending: {
|
|
1265
1278
|
matches: unloadedMatches,
|
|
@@ -1440,6 +1453,7 @@ function createRouter(userOptions) {
|
|
|
1440
1453
|
};
|
|
1441
1454
|
|
|
1442
1455
|
recurse([router.routeTree]);
|
|
1456
|
+
cascadeLoaderData(matches);
|
|
1443
1457
|
return matches;
|
|
1444
1458
|
},
|
|
1445
1459
|
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
@@ -1477,7 +1491,7 @@ function createRouter(userOptions) {
|
|
|
1477
1491
|
const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
|
|
1478
1492
|
[...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 => {
|
|
1479
1493
|
if (unloadedMatchIds.includes(match.matchId)) {
|
|
1480
|
-
match.
|
|
1494
|
+
match.invalidate();
|
|
1481
1495
|
}
|
|
1482
1496
|
});
|
|
1483
1497
|
},
|
|
@@ -1518,14 +1532,15 @@ function createRouter(userOptions) {
|
|
|
1518
1532
|
const next = router.buildNext(location);
|
|
1519
1533
|
return router.commitLocation(next, location.replace);
|
|
1520
1534
|
},
|
|
1521
|
-
navigate: async
|
|
1535
|
+
navigate: async _ref2 => {
|
|
1522
1536
|
let {
|
|
1523
1537
|
from,
|
|
1524
1538
|
to = '.',
|
|
1525
1539
|
search,
|
|
1526
1540
|
hash,
|
|
1527
|
-
replace
|
|
1528
|
-
|
|
1541
|
+
replace,
|
|
1542
|
+
params
|
|
1543
|
+
} = _ref2;
|
|
1529
1544
|
// If this link simply reloads the current route,
|
|
1530
1545
|
// make sure it has a new key so it will trigger a data refresh
|
|
1531
1546
|
// If this `to` is a valid external URL, return
|
|
@@ -1544,11 +1559,13 @@ function createRouter(userOptions) {
|
|
|
1544
1559
|
from: fromString,
|
|
1545
1560
|
to: toString,
|
|
1546
1561
|
search,
|
|
1547
|
-
hash
|
|
1562
|
+
hash,
|
|
1563
|
+
replace,
|
|
1564
|
+
params
|
|
1548
1565
|
});
|
|
1549
1566
|
},
|
|
1550
|
-
buildLink:
|
|
1551
|
-
var _preload,
|
|
1567
|
+
buildLink: _ref3 => {
|
|
1568
|
+
var _preload, _ref4, _ref5;
|
|
1552
1569
|
|
|
1553
1570
|
let {
|
|
1554
1571
|
from,
|
|
@@ -1563,7 +1580,7 @@ function createRouter(userOptions) {
|
|
|
1563
1580
|
preloadMaxAge: userPreloadMaxAge,
|
|
1564
1581
|
preloadDelay: userPreloadDelay,
|
|
1565
1582
|
disabled
|
|
1566
|
-
} =
|
|
1583
|
+
} = _ref3;
|
|
1567
1584
|
|
|
1568
1585
|
// If this link simply reloads the current route,
|
|
1569
1586
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -1587,8 +1604,8 @@ function createRouter(userOptions) {
|
|
|
1587
1604
|
};
|
|
1588
1605
|
const next = router.buildNext(nextOpts);
|
|
1589
1606
|
preload = (_preload = preload) != null ? _preload : router.options.defaultLinkPreload;
|
|
1590
|
-
const preloadMaxAge = (
|
|
1591
|
-
const preloadDelay = (
|
|
1607
|
+
const preloadMaxAge = (_ref4 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref4 : 2000;
|
|
1608
|
+
const preloadDelay = (_ref5 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref5 : 50; // Compare path/hash for matches
|
|
1592
1609
|
|
|
1593
1610
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
1594
1611
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
@@ -1662,11 +1679,11 @@ function createRouter(userOptions) {
|
|
|
1662
1679
|
},
|
|
1663
1680
|
__experimental__createSnapshot: () => {
|
|
1664
1681
|
return _extends$1({}, router.state, {
|
|
1665
|
-
matches: router.state.matches.map(
|
|
1682
|
+
matches: router.state.matches.map(_ref6 => {
|
|
1666
1683
|
let {
|
|
1667
1684
|
routeLoaderData: loaderData,
|
|
1668
1685
|
matchId
|
|
1669
|
-
} =
|
|
1686
|
+
} = _ref6;
|
|
1670
1687
|
return {
|
|
1671
1688
|
matchId,
|
|
1672
1689
|
loaderData
|
|
@@ -1716,10 +1733,12 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1716
1733
|
status: 'pending',
|
|
1717
1734
|
submission
|
|
1718
1735
|
};
|
|
1736
|
+
action.current = actionState;
|
|
1719
1737
|
action.latest = actionState;
|
|
1720
1738
|
action.pending.push(actionState);
|
|
1721
1739
|
router.state = _extends$1({}, router.state, {
|
|
1722
|
-
|
|
1740
|
+
currentAction: actionState,
|
|
1741
|
+
latestAction: actionState
|
|
1723
1742
|
});
|
|
1724
1743
|
router.notify();
|
|
1725
1744
|
|
|
@@ -1743,11 +1762,10 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1743
1762
|
actionState.status = 'error';
|
|
1744
1763
|
} finally {
|
|
1745
1764
|
action.pending = action.pending.filter(d => d !== actionState);
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
}
|
|
1750
|
-
|
|
1765
|
+
router.removeActionQueue.push({
|
|
1766
|
+
action,
|
|
1767
|
+
actionState
|
|
1768
|
+
});
|
|
1751
1769
|
router.notify();
|
|
1752
1770
|
}
|
|
1753
1771
|
}
|
|
@@ -1834,16 +1852,17 @@ function createRouteMatch(router, route, opts) {
|
|
|
1834
1852
|
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
1835
1853
|
delete routeMatch.__.pendingMinPromise;
|
|
1836
1854
|
},
|
|
1837
|
-
setParentMatch: parentMatch => {
|
|
1838
|
-
|
|
1839
|
-
},
|
|
1840
|
-
addChildMatch: childMatch => {
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1855
|
+
// setParentMatch: (parentMatch?: RouteMatch) => {
|
|
1856
|
+
// routeMatch.parentMatch = parentMatch
|
|
1857
|
+
// },
|
|
1858
|
+
// addChildMatch: (childMatch: RouteMatch) => {
|
|
1859
|
+
// if (
|
|
1860
|
+
// routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
|
|
1861
|
+
// ) {
|
|
1862
|
+
// return
|
|
1863
|
+
// }
|
|
1864
|
+
// routeMatch.childMatches.push(childMatch)
|
|
1865
|
+
// },
|
|
1847
1866
|
validate: () => {
|
|
1848
1867
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1849
1868
|
|
|
@@ -1880,6 +1899,9 @@ function createRouteMatch(router, route, opts) {
|
|
|
1880
1899
|
|
|
1881
1900
|
routeMatch.__.cancelPending();
|
|
1882
1901
|
},
|
|
1902
|
+
invalidate: () => {
|
|
1903
|
+
routeMatch.isInvalid = true;
|
|
1904
|
+
},
|
|
1883
1905
|
load: async () => {
|
|
1884
1906
|
const id = '' + Date.now() + Math.random();
|
|
1885
1907
|
routeMatch.__.latestId = id; // If the match was in an error state, set it
|
|
@@ -1947,7 +1969,6 @@ function createRouteMatch(router, route, opts) {
|
|
|
1947
1969
|
}
|
|
1948
1970
|
|
|
1949
1971
|
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1950
|
-
cascadeLoaderData(routeMatch);
|
|
1951
1972
|
routeMatch.error = undefined;
|
|
1952
1973
|
routeMatch.status = 'success';
|
|
1953
1974
|
routeMatch.updatedAt = Date.now();
|
|
@@ -2007,16 +2028,14 @@ function createRouteMatch(router, route, opts) {
|
|
|
2007
2028
|
return routeMatch;
|
|
2008
2029
|
}
|
|
2009
2030
|
|
|
2010
|
-
function cascadeLoaderData(
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
}
|
|
2031
|
+
function cascadeLoaderData(matches) {
|
|
2032
|
+
matches.forEach((match, index) => {
|
|
2033
|
+
const parent = matches[index - 1];
|
|
2014
2034
|
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
}
|
|
2035
|
+
if (parent) {
|
|
2036
|
+
match.loaderData = replaceEqualDeep(match.loaderData, _extends$1({}, parent.loaderData, match.routeLoaderData));
|
|
2037
|
+
}
|
|
2038
|
+
});
|
|
2020
2039
|
}
|
|
2021
2040
|
|
|
2022
2041
|
function matchPathname(currentPathname, matchLocation) {
|
|
@@ -2548,29 +2567,33 @@ function RouterProvider(_ref2) {
|
|
|
2548
2567
|
value: router.state.matches
|
|
2549
2568
|
}, children != null ? children : /*#__PURE__*/React.createElement(Outlet, null)));
|
|
2550
2569
|
}
|
|
2570
|
+
|
|
2551
2571
|
function useRouter() {
|
|
2552
2572
|
const value = React.useContext(routerContext);
|
|
2553
2573
|
warning(!value, 'useRouter must be used inside a <Router> component!');
|
|
2554
2574
|
useRouterSubscription(value.router);
|
|
2555
2575
|
return value.router;
|
|
2556
2576
|
}
|
|
2577
|
+
|
|
2557
2578
|
function useMatches() {
|
|
2558
2579
|
return React.useContext(matchesContext);
|
|
2559
|
-
}
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2580
|
+
} // function useParentMatches(): RouteMatch[] {
|
|
2581
|
+
// const router = useRouter()
|
|
2582
|
+
// const match = useMatch()
|
|
2583
|
+
// const matches = router.state.matches
|
|
2584
|
+
// return matches.slice(
|
|
2585
|
+
// 0,
|
|
2586
|
+
// matches.findIndex((d) => d.matchId === match.matchId) - 1,
|
|
2587
|
+
// )
|
|
2588
|
+
// }
|
|
2564
2589
|
|
|
2565
|
-
const matches = router.state.matches;
|
|
2566
|
-
return matches.slice(0, matches.findIndex(d => d.matchId === match.matchId) - 1);
|
|
2567
|
-
}
|
|
2568
2590
|
|
|
2569
2591
|
function _useMatch() {
|
|
2570
2592
|
var _useMatches;
|
|
2571
2593
|
|
|
2572
2594
|
return (_useMatches = useMatches()) == null ? void 0 : _useMatches[0];
|
|
2573
2595
|
}
|
|
2596
|
+
|
|
2574
2597
|
function Outlet() {
|
|
2575
2598
|
var _ref3, _childMatch$options$c;
|
|
2576
2599
|
|
|
@@ -2704,5 +2727,5 @@ function DefaultCatchBoundary(_ref6) {
|
|
|
2704
2727
|
}, "If you are the owner of this website, it's highly recommended that you configure your own custom Catch/Error boundaries for the router. You can optionally configure a boundary for each route."));
|
|
2705
2728
|
}
|
|
2706
2729
|
|
|
2707
|
-
export { DefaultCatchBoundary, MatchesProvider, Outlet, RouterProvider, createBrowserHistory, createHashHistory, createMemoryHistory, createReactRouter, createRoute, createRouteConfig, createRouteMatch, createRouter, defaultParseSearch, defaultStringifySearch, functionalUpdate, invariant, last, matchByPath, matchPathname, parsePathname, parseSearchWith, replaceEqualDeep, _resolvePath as resolvePath, rootRouteId, stringifySearchWith,
|
|
2730
|
+
export { DefaultCatchBoundary, MatchesProvider, Outlet, RouterProvider, createBrowserHistory, createHashHistory, createMemoryHistory, createReactRouter, createRoute, createRouteConfig, createRouteMatch, createRouter, defaultParseSearch, defaultStringifySearch, functionalUpdate, invariant, last, matchByPath, matchPathname, parsePathname, parseSearchWith, replaceEqualDeep, _resolvePath as resolvePath, rootRouteId, stringifySearchWith, warning };
|
|
2708
2731
|
//# sourceMappingURL=index.js.map
|