@tanstack/react-router 0.0.1-alpha.3 → 0.0.1-alpha.4
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 +6 -18
- package/build/cjs/react-router/src/index.js.map +1 -1
- package/build/cjs/router-core/build/esm/index.js +85 -54
- package/build/cjs/router-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +90 -73
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +29 -29
- package/build/umd/index.development.js +85 -70
- 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 +30 -33
package/build/esm/index.js
CHANGED
|
@@ -880,6 +880,20 @@ function parsePath(path) {
|
|
|
880
880
|
return parsedPath;
|
|
881
881
|
}
|
|
882
882
|
|
|
883
|
+
var isProduction = process.env.NODE_ENV === 'production';
|
|
884
|
+
var prefix = 'Invariant failed';
|
|
885
|
+
function invariant(condition, message) {
|
|
886
|
+
if (condition) {
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
if (isProduction) {
|
|
890
|
+
throw new Error(prefix);
|
|
891
|
+
}
|
|
892
|
+
var provided = typeof message === 'function' ? message() : message;
|
|
893
|
+
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
|
894
|
+
throw new Error(value);
|
|
895
|
+
}
|
|
896
|
+
|
|
883
897
|
// @ts-nocheck
|
|
884
898
|
// We're inlining qss here for compression's sake, but we've included it as a hard dependency for the MIT license it requires.
|
|
885
899
|
function encode(obj, pfx) {
|
|
@@ -933,7 +947,7 @@ function decode(str) {
|
|
|
933
947
|
return out;
|
|
934
948
|
}
|
|
935
949
|
|
|
936
|
-
const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId) {
|
|
950
|
+
const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
|
|
937
951
|
if (options === void 0) {
|
|
938
952
|
options = {};
|
|
939
953
|
}
|
|
@@ -944,8 +958,6 @@ const createRouteConfig = function createRouteConfig(options, children, isRoot,
|
|
|
944
958
|
|
|
945
959
|
if (isRoot) {
|
|
946
960
|
options.path = rootRouteId;
|
|
947
|
-
} else {
|
|
948
|
-
warning(!options.path, 'Routes must have a path property.');
|
|
949
961
|
} // Strip the root from parentIds
|
|
950
962
|
|
|
951
963
|
|
|
@@ -953,13 +965,14 @@ const createRouteConfig = function createRouteConfig(options, children, isRoot,
|
|
|
953
965
|
parentId = '';
|
|
954
966
|
}
|
|
955
967
|
|
|
956
|
-
let path =
|
|
968
|
+
let path = isRoot ? rootRouteId : options.path; // If the path is anything other than an index path, trim it up
|
|
957
969
|
|
|
958
|
-
if (path !== '/') {
|
|
970
|
+
if (path && path !== '/') {
|
|
959
971
|
path = trimPath(path);
|
|
960
972
|
}
|
|
961
973
|
|
|
962
|
-
|
|
974
|
+
const routeId = path || options.id;
|
|
975
|
+
let id = joinPaths([parentId, routeId]);
|
|
963
976
|
|
|
964
977
|
if (path === rootRouteId) {
|
|
965
978
|
path = '/';
|
|
@@ -969,14 +982,15 @@ const createRouteConfig = function createRouteConfig(options, children, isRoot,
|
|
|
969
982
|
id = joinPaths(['/', id]);
|
|
970
983
|
}
|
|
971
984
|
|
|
972
|
-
const fullPath = id === rootRouteId ? '/' : trimPathRight(
|
|
985
|
+
const fullPath = id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]));
|
|
973
986
|
return {
|
|
974
987
|
id: id,
|
|
988
|
+
routeId: routeId,
|
|
975
989
|
path: path,
|
|
976
990
|
fullPath: fullPath,
|
|
977
991
|
options: options,
|
|
978
992
|
children,
|
|
979
|
-
addChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id)), false, parentId)
|
|
993
|
+
addChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)), false, parentId, parentPath)
|
|
980
994
|
};
|
|
981
995
|
};
|
|
982
996
|
const rootRouteId = '__root__';
|
|
@@ -1352,55 +1366,76 @@ function createRouter(userOptions) {
|
|
|
1352
1366
|
|
|
1353
1367
|
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 : [])];
|
|
1354
1368
|
|
|
1355
|
-
const recurse = async
|
|
1356
|
-
var _parentMatch$params, _router$options$filte,
|
|
1369
|
+
const recurse = async routes => {
|
|
1370
|
+
var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
|
|
1357
1371
|
|
|
1372
|
+
const parentMatch = last(matches);
|
|
1358
1373
|
let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
|
|
1359
1374
|
const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
|
|
1360
|
-
|
|
1361
|
-
var _route$childRoutes, _route$options$caseSe;
|
|
1362
|
-
|
|
1363
|
-
const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length);
|
|
1364
|
-
const matchParams = matchPathname(pathname, {
|
|
1365
|
-
to: route.fullPath,
|
|
1366
|
-
fuzzy,
|
|
1367
|
-
caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
|
|
1368
|
-
});
|
|
1375
|
+
let foundRoutes = [];
|
|
1369
1376
|
|
|
1370
|
-
|
|
1371
|
-
|
|
1377
|
+
const findMatchInRoutes = (parentRoutes, routes) => {
|
|
1378
|
+
routes.some(route => {
|
|
1379
|
+
var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
|
|
1372
1380
|
|
|
1373
|
-
|
|
1374
|
-
|
|
1381
|
+
if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
|
|
1382
|
+
return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
|
|
1383
|
+
}
|
|
1375
1384
|
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1385
|
+
const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
|
|
1386
|
+
const matchParams = matchPathname(pathname, {
|
|
1387
|
+
to: route.fullPath,
|
|
1388
|
+
fuzzy,
|
|
1389
|
+
caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
|
|
1390
|
+
});
|
|
1391
|
+
|
|
1392
|
+
if (matchParams) {
|
|
1393
|
+
let parsedParams;
|
|
1394
|
+
|
|
1395
|
+
try {
|
|
1396
|
+
var _route$options$parseP;
|
|
1397
|
+
|
|
1398
|
+
parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
|
|
1399
|
+
} catch (err) {
|
|
1400
|
+
if (opts != null && opts.strictParseParams) {
|
|
1401
|
+
throw err;
|
|
1402
|
+
}
|
|
1380
1403
|
}
|
|
1404
|
+
|
|
1405
|
+
params = _extends$1({}, params, parsedParams);
|
|
1381
1406
|
}
|
|
1382
1407
|
|
|
1383
|
-
|
|
1384
|
-
|
|
1408
|
+
if (!!matchParams) {
|
|
1409
|
+
foundRoutes = [...parentRoutes, route];
|
|
1410
|
+
}
|
|
1385
1411
|
|
|
1386
|
-
|
|
1387
|
-
|
|
1412
|
+
return !!foundRoutes.length;
|
|
1413
|
+
});
|
|
1414
|
+
return !!foundRoutes.length;
|
|
1415
|
+
};
|
|
1388
1416
|
|
|
1389
|
-
|
|
1417
|
+
findMatchInRoutes([], filteredRoutes);
|
|
1418
|
+
|
|
1419
|
+
if (!foundRoutes.length) {
|
|
1390
1420
|
return;
|
|
1391
1421
|
}
|
|
1392
1422
|
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
params,
|
|
1398
|
-
|
|
1423
|
+
foundRoutes.forEach(foundRoute => {
|
|
1424
|
+
var _router$preloadCache$;
|
|
1425
|
+
|
|
1426
|
+
const interpolatedPath = interpolatePath(foundRoute.routePath, params);
|
|
1427
|
+
const matchId = interpolatePath(foundRoute.routeId, params, true);
|
|
1428
|
+
const match = existingMatches.find(d => d.matchId === matchId) || ((_router$preloadCache$ = router.preloadCache[matchId]) == null ? void 0 : _router$preloadCache$.match) || createRouteMatch(router, foundRoute, {
|
|
1429
|
+
matchId,
|
|
1430
|
+
params,
|
|
1431
|
+
pathname: joinPaths([pathname, interpolatedPath])
|
|
1432
|
+
});
|
|
1433
|
+
matches.push(match);
|
|
1399
1434
|
});
|
|
1400
|
-
|
|
1435
|
+
const foundRoute = last(foundRoutes);
|
|
1401
1436
|
|
|
1402
|
-
if ((
|
|
1403
|
-
recurse(
|
|
1437
|
+
if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
|
|
1438
|
+
recurse(foundRoute.childRoutes);
|
|
1404
1439
|
}
|
|
1405
1440
|
};
|
|
1406
1441
|
|
|
@@ -1504,14 +1539,7 @@ function createRouter(userOptions) {
|
|
|
1504
1539
|
isExternal = true;
|
|
1505
1540
|
} catch (e) {}
|
|
1506
1541
|
|
|
1507
|
-
|
|
1508
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1509
|
-
throw new Error('Attempting to navigate to external url with router.navigate!');
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
return;
|
|
1513
|
-
}
|
|
1514
|
-
|
|
1542
|
+
invariant(!isExternal, 'Attempting to navigate to external url with router.navigate!');
|
|
1515
1543
|
return router._navigate({
|
|
1516
1544
|
from: fromString,
|
|
1517
1545
|
to: toString,
|
|
@@ -1666,13 +1694,14 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1666
1694
|
// ]).replace(new RegExp(`^${rootRouteId}`), '')
|
|
1667
1695
|
// ) as TRouteInfo['id']
|
|
1668
1696
|
const {
|
|
1669
|
-
id
|
|
1697
|
+
id,
|
|
1698
|
+
routeId,
|
|
1670
1699
|
path: routePath,
|
|
1671
1700
|
fullPath
|
|
1672
1701
|
} = routeConfig;
|
|
1673
1702
|
|
|
1674
|
-
const action = router.state.actions[
|
|
1675
|
-
router.state.actions[
|
|
1703
|
+
const action = router.state.actions[id] || (() => {
|
|
1704
|
+
router.state.actions[id] = {
|
|
1676
1705
|
pending: [],
|
|
1677
1706
|
submit: async (submission, actionOpts) => {
|
|
1678
1707
|
var _actionOpts$invalidat;
|
|
@@ -1723,11 +1752,12 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1723
1752
|
}
|
|
1724
1753
|
}
|
|
1725
1754
|
};
|
|
1726
|
-
return router.state.actions[
|
|
1755
|
+
return router.state.actions[id];
|
|
1727
1756
|
})();
|
|
1728
1757
|
|
|
1729
1758
|
let route = {
|
|
1730
|
-
routeId,
|
|
1759
|
+
routeId: id,
|
|
1760
|
+
routeRouteId: routeId,
|
|
1731
1761
|
routePath,
|
|
1732
1762
|
fullPath,
|
|
1733
1763
|
options,
|
|
@@ -2464,34 +2494,21 @@ function createReactRouter(opts) {
|
|
|
2464
2494
|
useRoute: routeId => {
|
|
2465
2495
|
const route = router.getRoute(routeId);
|
|
2466
2496
|
useRouterSubscription(router);
|
|
2467
|
-
|
|
2468
|
-
if (!route) {
|
|
2469
|
-
throw new Error("Could not find a route for route \"" + routeId + "\"! Did you forget to add it to your route config?");
|
|
2470
|
-
}
|
|
2471
|
-
|
|
2497
|
+
invariant(route, "Could not find a route for route \"" + routeId + "\"! Did you forget to add it to your route config?");
|
|
2472
2498
|
return route;
|
|
2473
2499
|
},
|
|
2474
2500
|
useMatch: routeId => {
|
|
2475
|
-
|
|
2476
|
-
throw new Error("\"" + rootRouteId + "\" cannot be used with useMatch! Did you mean to useRoute(\"" + rootRouteId + "\")?");
|
|
2477
|
-
}
|
|
2501
|
+
invariant(routeId !== rootRouteId, "\"" + rootRouteId + "\" cannot be used with useMatch! Did you mean to useRoute(\"" + rootRouteId + "\")?");
|
|
2478
2502
|
|
|
2479
2503
|
const runtimeMatch = _useMatch();
|
|
2480
2504
|
|
|
2481
2505
|
const match = router.state.matches.find(d => d.routeId === routeId);
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
throw new Error("Could not find a match for route \"" + routeId + "\" being rendered in this component!");
|
|
2485
|
-
}
|
|
2486
|
-
|
|
2487
|
-
if (runtimeMatch.routeId !== (match == null ? void 0 : match.routeId)) {
|
|
2488
|
-
throw new Error("useMatch('" + (match == null ? void 0 : match.routeId) + "') is being called in a component that is meant to render the '" + runtimeMatch.routeId + "' route. Did you mean to 'useRoute(" + (match == null ? void 0 : match.routeId) + ")' instead?");
|
|
2489
|
-
}
|
|
2490
|
-
|
|
2506
|
+
invariant(match, "Could not find a match for route \"" + routeId + "\" being rendered in this component!");
|
|
2507
|
+
invariant(runtimeMatch.routeId == (match == null ? void 0 : match.routeId), "useMatch('" + (match == null ? void 0 : match.routeId) + "') is being called in a component that is meant to render the '" + runtimeMatch.routeId + "' route. Did you mean to 'useRoute(" + (match == null ? void 0 : match.routeId) + ")' instead?");
|
|
2491
2508
|
useRouterSubscription(router);
|
|
2492
2509
|
|
|
2493
2510
|
if (!match) {
|
|
2494
|
-
|
|
2511
|
+
invariant('Match not found!');
|
|
2495
2512
|
}
|
|
2496
2513
|
|
|
2497
2514
|
return match;
|
|
@@ -2687,5 +2704,5 @@ function DefaultCatchBoundary(_ref6) {
|
|
|
2687
2704
|
}, "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."));
|
|
2688
2705
|
}
|
|
2689
2706
|
|
|
2690
|
-
export { DefaultCatchBoundary, MatchesProvider, Outlet, RouterProvider, createBrowserHistory, createHashHistory, createMemoryHistory, createReactRouter, createRoute, createRouteConfig, createRouteMatch, createRouter, defaultParseSearch, defaultStringifySearch, functionalUpdate, last, matchByPath, matchPathname, parsePathname, parseSearchWith, replaceEqualDeep, _resolvePath as resolvePath, rootRouteId, stringifySearchWith, _useMatch as useMatch, useMatches, useParentMatches, useRouter, warning };
|
|
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, _useMatch as useMatch, useMatches, useParentMatches, useRouter, warning };
|
|
2691
2708
|
//# sourceMappingURL=index.js.map
|