@tanstack/router-core 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/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +30 -0
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +1 -0
- package/build/cjs/packages/router-core/src/index.js +72 -54
- package/build/cjs/packages/router-core/src/index.js.map +1 -1
- package/build/esm/index.js +85 -55
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +60 -35
- package/build/types/index.d.ts +49 -34
- package/build/umd/index.development.js +81 -52
- 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 -1
- package/src/index.ts +219 -142
- package/src/createRoutes.test.ts +0 -328
package/build/esm/index.js
CHANGED
|
@@ -835,6 +835,20 @@ function parsePath(path) {
|
|
|
835
835
|
return parsedPath;
|
|
836
836
|
}
|
|
837
837
|
|
|
838
|
+
var isProduction = process.env.NODE_ENV === 'production';
|
|
839
|
+
var prefix = 'Invariant failed';
|
|
840
|
+
function invariant(condition, message) {
|
|
841
|
+
if (condition) {
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
if (isProduction) {
|
|
845
|
+
throw new Error(prefix);
|
|
846
|
+
}
|
|
847
|
+
var provided = typeof message === 'function' ? message() : message;
|
|
848
|
+
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
|
849
|
+
throw new Error(value);
|
|
850
|
+
}
|
|
851
|
+
|
|
838
852
|
// @ts-nocheck
|
|
839
853
|
// We're inlining qss here for compression's sake, but we've included it as a hard dependency for the MIT license it requires.
|
|
840
854
|
function encode(obj, pfx) {
|
|
@@ -888,7 +902,7 @@ function decode(str) {
|
|
|
888
902
|
return out;
|
|
889
903
|
}
|
|
890
904
|
|
|
891
|
-
const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId) {
|
|
905
|
+
const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
|
|
892
906
|
if (options === void 0) {
|
|
893
907
|
options = {};
|
|
894
908
|
}
|
|
@@ -899,8 +913,6 @@ const createRouteConfig = function createRouteConfig(options, children, isRoot,
|
|
|
899
913
|
|
|
900
914
|
if (isRoot) {
|
|
901
915
|
options.path = rootRouteId;
|
|
902
|
-
} else {
|
|
903
|
-
warning(!options.path, 'Routes must have a path property.');
|
|
904
916
|
} // Strip the root from parentIds
|
|
905
917
|
|
|
906
918
|
|
|
@@ -908,13 +920,14 @@ const createRouteConfig = function createRouteConfig(options, children, isRoot,
|
|
|
908
920
|
parentId = '';
|
|
909
921
|
}
|
|
910
922
|
|
|
911
|
-
let path =
|
|
923
|
+
let path = isRoot ? rootRouteId : options.path; // If the path is anything other than an index path, trim it up
|
|
912
924
|
|
|
913
|
-
if (path !== '/') {
|
|
925
|
+
if (path && path !== '/') {
|
|
914
926
|
path = trimPath(path);
|
|
915
927
|
}
|
|
916
928
|
|
|
917
|
-
|
|
929
|
+
const routeId = path || options.id;
|
|
930
|
+
let id = joinPaths([parentId, routeId]);
|
|
918
931
|
|
|
919
932
|
if (path === rootRouteId) {
|
|
920
933
|
path = '/';
|
|
@@ -924,14 +937,15 @@ const createRouteConfig = function createRouteConfig(options, children, isRoot,
|
|
|
924
937
|
id = joinPaths(['/', id]);
|
|
925
938
|
}
|
|
926
939
|
|
|
927
|
-
const fullPath = id === rootRouteId ? '/' : trimPathRight(
|
|
940
|
+
const fullPath = id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]));
|
|
928
941
|
return {
|
|
929
942
|
id: id,
|
|
943
|
+
routeId: routeId,
|
|
930
944
|
path: path,
|
|
931
945
|
fullPath: fullPath,
|
|
932
946
|
options: options,
|
|
933
947
|
children,
|
|
934
|
-
addChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id)), false, parentId)
|
|
948
|
+
addChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)), false, parentId, parentPath)
|
|
935
949
|
};
|
|
936
950
|
};
|
|
937
951
|
const rootRouteId = '__root__';
|
|
@@ -1307,55 +1321,76 @@ function createRouter(userOptions) {
|
|
|
1307
1321
|
|
|
1308
1322
|
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 : [])];
|
|
1309
1323
|
|
|
1310
|
-
const recurse = async
|
|
1311
|
-
var _parentMatch$params, _router$options$filte,
|
|
1324
|
+
const recurse = async routes => {
|
|
1325
|
+
var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
|
|
1312
1326
|
|
|
1327
|
+
const parentMatch = last(matches);
|
|
1313
1328
|
let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
|
|
1314
1329
|
const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
|
|
1315
|
-
|
|
1316
|
-
var _route$childRoutes, _route$options$caseSe;
|
|
1317
|
-
|
|
1318
|
-
const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length);
|
|
1319
|
-
const matchParams = matchPathname(pathname, {
|
|
1320
|
-
to: route.fullPath,
|
|
1321
|
-
fuzzy,
|
|
1322
|
-
caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
|
|
1323
|
-
});
|
|
1330
|
+
let foundRoutes = [];
|
|
1324
1331
|
|
|
1325
|
-
|
|
1326
|
-
|
|
1332
|
+
const findMatchInRoutes = (parentRoutes, routes) => {
|
|
1333
|
+
routes.some(route => {
|
|
1334
|
+
var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
|
|
1327
1335
|
|
|
1328
|
-
|
|
1329
|
-
|
|
1336
|
+
if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
|
|
1337
|
+
return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
|
|
1338
|
+
}
|
|
1330
1339
|
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1340
|
+
const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
|
|
1341
|
+
const matchParams = matchPathname(pathname, {
|
|
1342
|
+
to: route.fullPath,
|
|
1343
|
+
fuzzy,
|
|
1344
|
+
caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
|
|
1345
|
+
});
|
|
1346
|
+
|
|
1347
|
+
if (matchParams) {
|
|
1348
|
+
let parsedParams;
|
|
1349
|
+
|
|
1350
|
+
try {
|
|
1351
|
+
var _route$options$parseP;
|
|
1352
|
+
|
|
1353
|
+
parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
|
|
1354
|
+
} catch (err) {
|
|
1355
|
+
if (opts != null && opts.strictParseParams) {
|
|
1356
|
+
throw err;
|
|
1357
|
+
}
|
|
1335
1358
|
}
|
|
1359
|
+
|
|
1360
|
+
params = _extends$1({}, params, parsedParams);
|
|
1336
1361
|
}
|
|
1337
1362
|
|
|
1338
|
-
|
|
1339
|
-
|
|
1363
|
+
if (!!matchParams) {
|
|
1364
|
+
foundRoutes = [...parentRoutes, route];
|
|
1365
|
+
}
|
|
1340
1366
|
|
|
1341
|
-
|
|
1342
|
-
|
|
1367
|
+
return !!foundRoutes.length;
|
|
1368
|
+
});
|
|
1369
|
+
return !!foundRoutes.length;
|
|
1370
|
+
};
|
|
1343
1371
|
|
|
1344
|
-
|
|
1372
|
+
findMatchInRoutes([], filteredRoutes);
|
|
1373
|
+
|
|
1374
|
+
if (!foundRoutes.length) {
|
|
1345
1375
|
return;
|
|
1346
1376
|
}
|
|
1347
1377
|
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
params,
|
|
1353
|
-
|
|
1378
|
+
foundRoutes.forEach(foundRoute => {
|
|
1379
|
+
var _router$preloadCache$;
|
|
1380
|
+
|
|
1381
|
+
const interpolatedPath = interpolatePath(foundRoute.routePath, params);
|
|
1382
|
+
const matchId = interpolatePath(foundRoute.routeId, params, true);
|
|
1383
|
+
const match = existingMatches.find(d => d.matchId === matchId) || ((_router$preloadCache$ = router.preloadCache[matchId]) == null ? void 0 : _router$preloadCache$.match) || createRouteMatch(router, foundRoute, {
|
|
1384
|
+
matchId,
|
|
1385
|
+
params,
|
|
1386
|
+
pathname: joinPaths([pathname, interpolatedPath])
|
|
1387
|
+
});
|
|
1388
|
+
matches.push(match);
|
|
1354
1389
|
});
|
|
1355
|
-
|
|
1390
|
+
const foundRoute = last(foundRoutes);
|
|
1356
1391
|
|
|
1357
|
-
if ((
|
|
1358
|
-
recurse(
|
|
1392
|
+
if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
|
|
1393
|
+
recurse(foundRoute.childRoutes);
|
|
1359
1394
|
}
|
|
1360
1395
|
};
|
|
1361
1396
|
|
|
@@ -1459,14 +1494,7 @@ function createRouter(userOptions) {
|
|
|
1459
1494
|
isExternal = true;
|
|
1460
1495
|
} catch (e) {}
|
|
1461
1496
|
|
|
1462
|
-
|
|
1463
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1464
|
-
throw new Error('Attempting to navigate to external url with router.navigate!');
|
|
1465
|
-
}
|
|
1466
|
-
|
|
1467
|
-
return;
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1497
|
+
invariant(!isExternal, 'Attempting to navigate to external url with router.navigate!');
|
|
1470
1498
|
return router._navigate({
|
|
1471
1499
|
from: fromString,
|
|
1472
1500
|
to: toString,
|
|
@@ -1621,13 +1649,14 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1621
1649
|
// ]).replace(new RegExp(`^${rootRouteId}`), '')
|
|
1622
1650
|
// ) as TRouteInfo['id']
|
|
1623
1651
|
const {
|
|
1624
|
-
id
|
|
1652
|
+
id,
|
|
1653
|
+
routeId,
|
|
1625
1654
|
path: routePath,
|
|
1626
1655
|
fullPath
|
|
1627
1656
|
} = routeConfig;
|
|
1628
1657
|
|
|
1629
|
-
const action = router.state.actions[
|
|
1630
|
-
router.state.actions[
|
|
1658
|
+
const action = router.state.actions[id] || (() => {
|
|
1659
|
+
router.state.actions[id] = {
|
|
1631
1660
|
pending: [],
|
|
1632
1661
|
submit: async (submission, actionOpts) => {
|
|
1633
1662
|
var _actionOpts$invalidat;
|
|
@@ -1678,11 +1707,12 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1678
1707
|
}
|
|
1679
1708
|
}
|
|
1680
1709
|
};
|
|
1681
|
-
return router.state.actions[
|
|
1710
|
+
return router.state.actions[id];
|
|
1682
1711
|
})();
|
|
1683
1712
|
|
|
1684
1713
|
let route = {
|
|
1685
|
-
routeId,
|
|
1714
|
+
routeId: id,
|
|
1715
|
+
routeRouteId: routeId,
|
|
1686
1716
|
routePath,
|
|
1687
1717
|
fullPath,
|
|
1688
1718
|
options,
|
|
@@ -2293,5 +2323,5 @@ function last(arr) {
|
|
|
2293
2323
|
return arr[arr.length - 1];
|
|
2294
2324
|
}
|
|
2295
2325
|
|
|
2296
|
-
export { createBrowserHistory, createHashHistory, createMemoryHistory, createRoute, createRouteConfig, createRouteMatch, createRouter, defaultParseSearch, defaultStringifySearch, functionalUpdate, last, matchByPath, matchPathname, parsePathname, parseSearchWith, replaceEqualDeep, _resolvePath as resolvePath, rootRouteId, stringifySearchWith, warning };
|
|
2326
|
+
export { createBrowserHistory, createHashHistory, createMemoryHistory, createRoute, createRouteConfig, createRouteMatch, createRouter, defaultParseSearch, defaultStringifySearch, functionalUpdate, invariant, last, matchByPath, matchPathname, parsePathname, parseSearchWith, replaceEqualDeep, _resolvePath as resolvePath, rootRouteId, stringifySearchWith, warning };
|
|
2297
2327
|
//# sourceMappingURL=index.js.map
|