@tanstack/react-router 0.0.1-alpha.10 → 0.0.1-alpha.11
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 +24 -6
- package/build/cjs/react-router/src/index.js.map +1 -1
- package/build/cjs/router-core/build/esm/index.js +64 -30
- package/build/cjs/router-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +88 -36
- 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 +4 -6
- package/build/umd/index.development.js +88 -36
- 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 +52 -24
package/build/stats-html.html
CHANGED
|
@@ -4014,7 +4014,7 @@ var drawChart = (function (exports) {
|
|
|
4014
4014
|
</script>
|
|
4015
4015
|
<script>
|
|
4016
4016
|
/*<!--*/
|
|
4017
|
-
const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"uid":"
|
|
4017
|
+
const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"uid":"f71d-59","name":"\u0000rollupPluginBabelHelpers.js"},{"name":"packages","children":[{"name":"router-core/build/esm/index.js","uid":"f71d-61"},{"name":"react-router/src/index.tsx","uid":"f71d-63"}]}]}],"isRoot":true},"nodeParts":{"f71d-59":{"renderedLength":798,"gzipLength":366,"brotliLength":0,"mainUid":"f71d-58"},"f71d-61":{"renderedLength":74805,"gzipLength":15586,"brotliLength":0,"mainUid":"f71d-60"},"f71d-63":{"renderedLength":12706,"gzipLength":3314,"brotliLength":0,"mainUid":"f71d-62"}},"nodeMetas":{"f71d-58":{"id":"\u0000rollupPluginBabelHelpers.js","moduleParts":{"index.production.js":"f71d-59"},"imported":[],"importedBy":[{"uid":"f71d-62"}]},"f71d-60":{"id":"/packages/router-core/build/esm/index.js","moduleParts":{"index.production.js":"f71d-61"},"imported":[],"importedBy":[{"uid":"f71d-62"}]},"f71d-62":{"id":"/packages/react-router/src/index.tsx","moduleParts":{"index.production.js":"f71d-63"},"imported":[{"uid":"f71d-58"},{"uid":"f71d-64"},{"uid":"f71d-65"},{"uid":"f71d-60"}],"importedBy":[],"isEntry":true},"f71d-64":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"f71d-62"}],"isExternal":true},"f71d-65":{"id":"use-sync-external-store/shim","moduleParts":{},"imported":[],"importedBy":[{"uid":"f71d-62"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
|
|
4018
4018
|
|
|
4019
4019
|
const run = () => {
|
|
4020
4020
|
const width = window.innerWidth;
|
package/build/stats-react.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"name": "index.production.js",
|
|
8
8
|
"children": [
|
|
9
9
|
{
|
|
10
|
-
"uid": "
|
|
10
|
+
"uid": "f71d-67",
|
|
11
11
|
"name": "\u0000rollupPluginBabelHelpers.js"
|
|
12
12
|
},
|
|
13
13
|
{
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
"children": [
|
|
16
16
|
{
|
|
17
17
|
"name": "router-core/build/esm/index.js",
|
|
18
|
-
"uid": "
|
|
18
|
+
"uid": "f71d-69"
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
21
|
"name": "react-router/src/index.tsx",
|
|
22
|
-
"uid": "
|
|
22
|
+
"uid": "f71d-71"
|
|
23
23
|
}
|
|
24
24
|
]
|
|
25
25
|
}
|
|
@@ -29,90 +29,90 @@
|
|
|
29
29
|
"isRoot": true
|
|
30
30
|
},
|
|
31
31
|
"nodeParts": {
|
|
32
|
-
"
|
|
32
|
+
"f71d-67": {
|
|
33
33
|
"renderedLength": 798,
|
|
34
34
|
"gzipLength": 366,
|
|
35
35
|
"brotliLength": 0,
|
|
36
|
-
"mainUid": "
|
|
36
|
+
"mainUid": "f71d-66"
|
|
37
37
|
},
|
|
38
|
-
"
|
|
39
|
-
"renderedLength":
|
|
40
|
-
"gzipLength":
|
|
38
|
+
"f71d-69": {
|
|
39
|
+
"renderedLength": 74805,
|
|
40
|
+
"gzipLength": 15586,
|
|
41
41
|
"brotliLength": 0,
|
|
42
|
-
"mainUid": "
|
|
42
|
+
"mainUid": "f71d-68"
|
|
43
43
|
},
|
|
44
|
-
"
|
|
45
|
-
"renderedLength":
|
|
46
|
-
"gzipLength":
|
|
44
|
+
"f71d-71": {
|
|
45
|
+
"renderedLength": 12706,
|
|
46
|
+
"gzipLength": 3314,
|
|
47
47
|
"brotliLength": 0,
|
|
48
|
-
"mainUid": "
|
|
48
|
+
"mainUid": "f71d-70"
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"nodeMetas": {
|
|
52
|
-
"
|
|
52
|
+
"f71d-66": {
|
|
53
53
|
"id": "\u0000rollupPluginBabelHelpers.js",
|
|
54
54
|
"moduleParts": {
|
|
55
|
-
"index.production.js": "
|
|
55
|
+
"index.production.js": "f71d-67"
|
|
56
56
|
},
|
|
57
57
|
"imported": [],
|
|
58
58
|
"importedBy": [
|
|
59
59
|
{
|
|
60
|
-
"uid": "
|
|
60
|
+
"uid": "f71d-70"
|
|
61
61
|
}
|
|
62
62
|
]
|
|
63
63
|
},
|
|
64
|
-
"
|
|
64
|
+
"f71d-68": {
|
|
65
65
|
"id": "/packages/router-core/build/esm/index.js",
|
|
66
66
|
"moduleParts": {
|
|
67
|
-
"index.production.js": "
|
|
67
|
+
"index.production.js": "f71d-69"
|
|
68
68
|
},
|
|
69
69
|
"imported": [],
|
|
70
70
|
"importedBy": [
|
|
71
71
|
{
|
|
72
|
-
"uid": "
|
|
72
|
+
"uid": "f71d-70"
|
|
73
73
|
}
|
|
74
74
|
]
|
|
75
75
|
},
|
|
76
|
-
"
|
|
76
|
+
"f71d-70": {
|
|
77
77
|
"id": "/packages/react-router/src/index.tsx",
|
|
78
78
|
"moduleParts": {
|
|
79
|
-
"index.production.js": "
|
|
79
|
+
"index.production.js": "f71d-71"
|
|
80
80
|
},
|
|
81
81
|
"imported": [
|
|
82
82
|
{
|
|
83
|
-
"uid": "
|
|
83
|
+
"uid": "f71d-66"
|
|
84
84
|
},
|
|
85
85
|
{
|
|
86
|
-
"uid": "
|
|
86
|
+
"uid": "f71d-72"
|
|
87
87
|
},
|
|
88
88
|
{
|
|
89
|
-
"uid": "
|
|
89
|
+
"uid": "f71d-73"
|
|
90
90
|
},
|
|
91
91
|
{
|
|
92
|
-
"uid": "
|
|
92
|
+
"uid": "f71d-68"
|
|
93
93
|
}
|
|
94
94
|
],
|
|
95
95
|
"importedBy": [],
|
|
96
96
|
"isEntry": true
|
|
97
97
|
},
|
|
98
|
-
"
|
|
98
|
+
"f71d-72": {
|
|
99
99
|
"id": "react",
|
|
100
100
|
"moduleParts": {},
|
|
101
101
|
"imported": [],
|
|
102
102
|
"importedBy": [
|
|
103
103
|
{
|
|
104
|
-
"uid": "
|
|
104
|
+
"uid": "f71d-70"
|
|
105
105
|
}
|
|
106
106
|
],
|
|
107
107
|
"isExternal": true
|
|
108
108
|
},
|
|
109
|
-
"
|
|
109
|
+
"f71d-73": {
|
|
110
110
|
"id": "use-sync-external-store/shim",
|
|
111
111
|
"moduleParts": {},
|
|
112
112
|
"imported": [],
|
|
113
113
|
"importedBy": [
|
|
114
114
|
{
|
|
115
|
-
"uid": "
|
|
115
|
+
"uid": "f71d-70"
|
|
116
116
|
}
|
|
117
117
|
],
|
|
118
118
|
"isExternal": true
|
package/build/types/index.d.ts
CHANGED
|
@@ -9,18 +9,15 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
import * as React from 'react';
|
|
12
|
-
import { AnyRouteConfig, RouteConfig, AnyAllRouteInfo, AllRouteInfo,
|
|
12
|
+
import { AnyRouteConfig, RouteConfig, AnyAllRouteInfo, AllRouteInfo, RouterState, RouteMatch, ToOptions, MatchRouteOptions, RouteInfoByPath, ResolveRelativePath, NoInfer, DefaultAllRouteInfo, AnyRouteInfo, RouteInfo, CheckId, ToIdOption, ValidFromPath, LinkOptions, RouterOptions, Router } from '@tanstack/router-core';
|
|
13
13
|
export * from '@tanstack/router-core';
|
|
14
14
|
|
|
15
15
|
declare module '@tanstack/router-core' {
|
|
16
16
|
interface FrameworkGenerics {
|
|
17
17
|
Element: React.ReactNode;
|
|
18
|
-
|
|
19
|
-
params: Record<string, string>;
|
|
20
|
-
}) => Promise<React.ReactNode>;
|
|
21
|
-
SyncOrAsyncElement: React.ReactNode | FrameworkGenerics['AsyncElement'];
|
|
18
|
+
SyncOrAsyncElement: React.ReactNode | (() => Promise<any>);
|
|
22
19
|
}
|
|
23
|
-
interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>>
|
|
20
|
+
interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>> {
|
|
24
21
|
useState: () => RouterState;
|
|
25
22
|
useRoute: <TId extends keyof TAllRouteInfo['routeInfoById']>(routeId: TId) => Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>;
|
|
26
23
|
useMatch: <TId extends keyof TAllRouteInfo['routeInfoById']>(routeId: TId) => RouteMatch<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>;
|
|
@@ -35,6 +32,7 @@ declare module '@tanstack/router-core' {
|
|
|
35
32
|
}) => JSX.Element;
|
|
36
33
|
}
|
|
37
34
|
interface Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> {
|
|
35
|
+
useRoute: <TTo extends string = '.', TResolved extends string = ResolveRelativePath<TRouteInfo['id'], NoInfer<TTo>>>(routeId: CheckId<TAllRouteInfo, TResolved, ToIdOption<TAllRouteInfo, TRouteInfo['id'], TTo>>) => Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TResolved]>;
|
|
38
36
|
linkProps: <TTo extends string = '.'>(props: LinkPropsOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement>) => React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
39
37
|
Link: <TTo extends string = '.'>(props: LinkPropsOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement> & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {
|
|
40
38
|
children?: React.ReactNode | ((state: {
|
|
@@ -1321,6 +1321,40 @@
|
|
|
1321
1321
|
return router.state.actions[id];
|
|
1322
1322
|
})();
|
|
1323
1323
|
|
|
1324
|
+
const loader = router.state.loaders[id] || (() => {
|
|
1325
|
+
router.state.loaders[id] = {
|
|
1326
|
+
pending: [],
|
|
1327
|
+
fetch: async loaderContext => {
|
|
1328
|
+
if (!route) {
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
const loaderState = {
|
|
1333
|
+
loadedAt: Date.now(),
|
|
1334
|
+
loaderContext
|
|
1335
|
+
};
|
|
1336
|
+
loader.current = loaderState;
|
|
1337
|
+
loader.latest = loaderState;
|
|
1338
|
+
loader.pending.push(loaderState); // router.state = {
|
|
1339
|
+
// ...router.state,
|
|
1340
|
+
// currentAction: loaderState,
|
|
1341
|
+
// latestAction: loaderState,
|
|
1342
|
+
// }
|
|
1343
|
+
|
|
1344
|
+
router.notify();
|
|
1345
|
+
|
|
1346
|
+
try {
|
|
1347
|
+
return await (route.options.loader == null ? void 0 : route.options.loader(loaderContext));
|
|
1348
|
+
} finally {
|
|
1349
|
+
loader.pending = loader.pending.filter(d => d !== loaderState); // router.removeActionQueue.push({ loader, loaderState })
|
|
1350
|
+
|
|
1351
|
+
router.notify();
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
return router.state.loaders[id];
|
|
1356
|
+
})();
|
|
1357
|
+
|
|
1324
1358
|
let route = {
|
|
1325
1359
|
routeId: id,
|
|
1326
1360
|
routeRouteId: routeId,
|
|
@@ -1331,6 +1365,7 @@
|
|
|
1331
1365
|
childRoutes: undefined,
|
|
1332
1366
|
parentRoute: parent,
|
|
1333
1367
|
action,
|
|
1368
|
+
loader: loader,
|
|
1334
1369
|
buildLink: options => {
|
|
1335
1370
|
return router.buildLink(_extends({}, options, {
|
|
1336
1371
|
from: fullPath
|
|
@@ -1520,7 +1555,31 @@
|
|
|
1520
1555
|
hasLoaders: () => {
|
|
1521
1556
|
return !!(route.options.loader || elementTypes.some(d => typeof route.options[d] === 'function'));
|
|
1522
1557
|
},
|
|
1523
|
-
load: async
|
|
1558
|
+
load: async loaderOpts => {
|
|
1559
|
+
const now = Date.now();
|
|
1560
|
+
const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0; // If this is a preload, add it to the preload cache
|
|
1561
|
+
|
|
1562
|
+
if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
|
|
1563
|
+
// If the match is currently active, don't preload it
|
|
1564
|
+
if (router.state.matches.find(d => d.matchId === routeMatch.matchId)) {
|
|
1565
|
+
return;
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
router.matchCache[routeMatch.matchId] = {
|
|
1569
|
+
gc: now + loaderOpts.gcMaxAge,
|
|
1570
|
+
match: routeMatch
|
|
1571
|
+
};
|
|
1572
|
+
} // If the match is invalid, errored or idle, trigger it to load
|
|
1573
|
+
|
|
1574
|
+
|
|
1575
|
+
if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
|
|
1576
|
+
const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
|
|
1577
|
+
routeMatch.fetch({
|
|
1578
|
+
maxAge
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
},
|
|
1582
|
+
fetch: async opts => {
|
|
1524
1583
|
const id = '' + Date.now() + Math.random();
|
|
1525
1584
|
routeMatch.__.latestId = id; // If the match was in an error state, set it
|
|
1526
1585
|
// to a loading state again. Otherwise, keep it
|
|
@@ -1550,12 +1609,7 @@
|
|
|
1550
1609
|
return;
|
|
1551
1610
|
}
|
|
1552
1611
|
|
|
1553
|
-
|
|
1554
|
-
const res = await routeElement(routeMatch);
|
|
1555
|
-
routeMatch.__[type] = res;
|
|
1556
|
-
} else {
|
|
1557
|
-
routeMatch.__[type] = routeMatch.options[type];
|
|
1558
|
-
}
|
|
1612
|
+
routeMatch.__[type] = await router.options.createElement(routeElement);
|
|
1559
1613
|
}));
|
|
1560
1614
|
})();
|
|
1561
1615
|
|
|
@@ -1730,6 +1784,7 @@
|
|
|
1730
1784
|
location: null,
|
|
1731
1785
|
matches: [],
|
|
1732
1786
|
actions: {},
|
|
1787
|
+
loaders: {},
|
|
1733
1788
|
loaderData: {},
|
|
1734
1789
|
lastUpdated: Date.now(),
|
|
1735
1790
|
isFetching: false,
|
|
@@ -2066,32 +2121,11 @@
|
|
|
2066
2121
|
return matches;
|
|
2067
2122
|
},
|
|
2068
2123
|
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
2069
|
-
const now = Date.now();
|
|
2070
|
-
const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0;
|
|
2071
2124
|
const matchPromises = resolvedMatches.map(async match => {
|
|
2072
2125
|
// Validate the match (loads search params etc)
|
|
2073
|
-
match.__.validate();
|
|
2126
|
+
match.__.validate();
|
|
2074
2127
|
|
|
2075
|
-
|
|
2076
|
-
if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
|
|
2077
|
-
// If the match is currently active, don't preload it
|
|
2078
|
-
if (router.state.matches.find(d => d.matchId === match.matchId)) {
|
|
2079
|
-
return;
|
|
2080
|
-
}
|
|
2081
|
-
|
|
2082
|
-
router.matchCache[match.matchId] = {
|
|
2083
|
-
gc: now + loaderOpts.gcMaxAge,
|
|
2084
|
-
match
|
|
2085
|
-
};
|
|
2086
|
-
} // If the match is invalid, errored or idle, trigger it to load
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
if (match.status === 'success' && match.getIsInvalid() || match.status === 'error' || match.status === 'idle') {
|
|
2090
|
-
const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
|
|
2091
|
-
match.load({
|
|
2092
|
-
maxAge
|
|
2093
|
-
});
|
|
2094
|
-
}
|
|
2128
|
+
match.load(loaderOpts);
|
|
2095
2129
|
|
|
2096
2130
|
if (match.status === 'loading') {
|
|
2097
2131
|
// If requested, start the pending timers
|
|
@@ -2493,6 +2527,17 @@
|
|
|
2493
2527
|
function createReactRouter(opts) {
|
|
2494
2528
|
const makeRouteExt = (route, router) => {
|
|
2495
2529
|
return {
|
|
2530
|
+
useRoute: function useRoute(subRouteId) {
|
|
2531
|
+
if (subRouteId === void 0) {
|
|
2532
|
+
subRouteId = '.';
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2535
|
+
const resolvedRouteId = router.resolvePath(route.routeId, subRouteId);
|
|
2536
|
+
const resolvedRoute = router.getRoute(resolvedRouteId);
|
|
2537
|
+
useRouterSubscription(router);
|
|
2538
|
+
invariant(resolvedRoute, "Could not find a route for route \"" + resolvedRouteId + "\"! Did you forget to add it to your route config?");
|
|
2539
|
+
return resolvedRoute;
|
|
2540
|
+
},
|
|
2496
2541
|
linkProps: options => {
|
|
2497
2542
|
var _functionalUpdate, _functionalUpdate2;
|
|
2498
2543
|
|
|
@@ -2600,12 +2645,6 @@
|
|
|
2600
2645
|
useRouterSubscription(router);
|
|
2601
2646
|
return router.state;
|
|
2602
2647
|
},
|
|
2603
|
-
useRoute: routeId => {
|
|
2604
|
-
const route = router.getRoute(routeId);
|
|
2605
|
-
useRouterSubscription(router);
|
|
2606
|
-
invariant(route, "Could not find a route for route \"" + routeId + "\"! Did you forget to add it to your route config?");
|
|
2607
|
-
return route;
|
|
2608
|
-
},
|
|
2609
2648
|
useMatch: routeId => {
|
|
2610
2649
|
useRouterSubscription(router);
|
|
2611
2650
|
invariant(routeId !== rootRouteId, "\"" + rootRouteId + "\" cannot be used with useMatch! Did you mean to useRoute(\"" + rootRouteId + "\")?");
|
|
@@ -2633,6 +2672,19 @@
|
|
|
2633
2672
|
} = _ref;
|
|
2634
2673
|
const routeExt = makeRouteExt(route, router);
|
|
2635
2674
|
Object.assign(route, routeExt);
|
|
2675
|
+
},
|
|
2676
|
+
createElement: async element => {
|
|
2677
|
+
if (typeof element === 'function') {
|
|
2678
|
+
const res = await element(); // Support direct import() calls
|
|
2679
|
+
|
|
2680
|
+
if (typeof res === 'object' && res.default) {
|
|
2681
|
+
return /*#__PURE__*/React__namespace.createElement(res.default);
|
|
2682
|
+
} else {
|
|
2683
|
+
return res;
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
return element;
|
|
2636
2688
|
}
|
|
2637
2689
|
}));
|
|
2638
2690
|
return coreRouter;
|