@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.
@@ -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":"b6e9-21","name":"\u0000rollupPluginBabelHelpers.js"},{"name":"packages","children":[{"name":"router-core/build/esm/index.js","uid":"b6e9-23"},{"name":"react-router/src/index.tsx","uid":"b6e9-25"}]}]}],"isRoot":true},"nodeParts":{"b6e9-21":{"renderedLength":798,"gzipLength":366,"brotliLength":0,"mainUid":"b6e9-20"},"b6e9-23":{"renderedLength":68622,"gzipLength":14235,"brotliLength":0,"mainUid":"b6e9-22"},"b6e9-25":{"renderedLength":11932,"gzipLength":3067,"brotliLength":0,"mainUid":"b6e9-24"}},"nodeMetas":{"b6e9-20":{"id":"\u0000rollupPluginBabelHelpers.js","moduleParts":{"index.production.js":"b6e9-21"},"imported":[],"importedBy":[{"uid":"b6e9-24"}]},"b6e9-22":{"id":"/packages/router-core/build/esm/index.js","moduleParts":{"index.production.js":"b6e9-23"},"imported":[],"importedBy":[{"uid":"b6e9-24"}]},"b6e9-24":{"id":"/packages/react-router/src/index.tsx","moduleParts":{"index.production.js":"b6e9-25"},"imported":[{"uid":"b6e9-20"},{"uid":"b6e9-26"},{"uid":"b6e9-27"},{"uid":"b6e9-22"}],"importedBy":[],"isEntry":true},"b6e9-26":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"b6e9-24"}],"isExternal":true},"b6e9-27":{"id":"use-sync-external-store/shim","moduleParts":{},"imported":[],"importedBy":[{"uid":"b6e9-24"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4017
+ const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"uid":"c4e0-25","name":"\u0000rollupPluginBabelHelpers.js"},{"name":"packages","children":[{"name":"router-core/build/esm/index.js","uid":"c4e0-27"},{"name":"react-router/src/index.tsx","uid":"c4e0-29"}]}]}],"isRoot":true},"nodeParts":{"c4e0-25":{"renderedLength":798,"gzipLength":366,"brotliLength":0,"mainUid":"c4e0-24"},"c4e0-27":{"renderedLength":69609,"gzipLength":14467,"brotliLength":0,"mainUid":"c4e0-26"},"c4e0-29":{"renderedLength":11456,"gzipLength":2963,"brotliLength":0,"mainUid":"c4e0-28"}},"nodeMetas":{"c4e0-24":{"id":"\u0000rollupPluginBabelHelpers.js","moduleParts":{"index.production.js":"c4e0-25"},"imported":[],"importedBy":[{"uid":"c4e0-28"}]},"c4e0-26":{"id":"/packages/router-core/build/esm/index.js","moduleParts":{"index.production.js":"c4e0-27"},"imported":[],"importedBy":[{"uid":"c4e0-28"}]},"c4e0-28":{"id":"/packages/react-router/src/index.tsx","moduleParts":{"index.production.js":"c4e0-29"},"imported":[{"uid":"c4e0-24"},{"uid":"c4e0-30"},{"uid":"c4e0-31"},{"uid":"c4e0-26"}],"importedBy":[],"isEntry":true},"c4e0-30":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"c4e0-28"}],"isExternal":true},"c4e0-31":{"id":"use-sync-external-store/shim","moduleParts":{},"imported":[],"importedBy":[{"uid":"c4e0-28"}],"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;
@@ -7,7 +7,7 @@
7
7
  "name": "index.production.js",
8
8
  "children": [
9
9
  {
10
- "uid": "b6e9-29",
10
+ "uid": "c4e0-33",
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": "b6e9-31"
18
+ "uid": "c4e0-35"
19
19
  },
20
20
  {
21
21
  "name": "react-router/src/index.tsx",
22
- "uid": "b6e9-33"
22
+ "uid": "c4e0-37"
23
23
  }
24
24
  ]
25
25
  }
@@ -29,90 +29,90 @@
29
29
  "isRoot": true
30
30
  },
31
31
  "nodeParts": {
32
- "b6e9-29": {
32
+ "c4e0-33": {
33
33
  "renderedLength": 798,
34
34
  "gzipLength": 366,
35
35
  "brotliLength": 0,
36
- "mainUid": "b6e9-28"
36
+ "mainUid": "c4e0-32"
37
37
  },
38
- "b6e9-31": {
39
- "renderedLength": 68622,
40
- "gzipLength": 14235,
38
+ "c4e0-35": {
39
+ "renderedLength": 69609,
40
+ "gzipLength": 14467,
41
41
  "brotliLength": 0,
42
- "mainUid": "b6e9-30"
42
+ "mainUid": "c4e0-34"
43
43
  },
44
- "b6e9-33": {
45
- "renderedLength": 11932,
46
- "gzipLength": 3067,
44
+ "c4e0-37": {
45
+ "renderedLength": 11456,
46
+ "gzipLength": 2963,
47
47
  "brotliLength": 0,
48
- "mainUid": "b6e9-32"
48
+ "mainUid": "c4e0-36"
49
49
  }
50
50
  },
51
51
  "nodeMetas": {
52
- "b6e9-28": {
52
+ "c4e0-32": {
53
53
  "id": "\u0000rollupPluginBabelHelpers.js",
54
54
  "moduleParts": {
55
- "index.production.js": "b6e9-29"
55
+ "index.production.js": "c4e0-33"
56
56
  },
57
57
  "imported": [],
58
58
  "importedBy": [
59
59
  {
60
- "uid": "b6e9-32"
60
+ "uid": "c4e0-36"
61
61
  }
62
62
  ]
63
63
  },
64
- "b6e9-30": {
64
+ "c4e0-34": {
65
65
  "id": "/packages/router-core/build/esm/index.js",
66
66
  "moduleParts": {
67
- "index.production.js": "b6e9-31"
67
+ "index.production.js": "c4e0-35"
68
68
  },
69
69
  "imported": [],
70
70
  "importedBy": [
71
71
  {
72
- "uid": "b6e9-32"
72
+ "uid": "c4e0-36"
73
73
  }
74
74
  ]
75
75
  },
76
- "b6e9-32": {
76
+ "c4e0-36": {
77
77
  "id": "/packages/react-router/src/index.tsx",
78
78
  "moduleParts": {
79
- "index.production.js": "b6e9-33"
79
+ "index.production.js": "c4e0-37"
80
80
  },
81
81
  "imported": [
82
82
  {
83
- "uid": "b6e9-28"
83
+ "uid": "c4e0-32"
84
84
  },
85
85
  {
86
- "uid": "b6e9-34"
86
+ "uid": "c4e0-38"
87
87
  },
88
88
  {
89
- "uid": "b6e9-35"
89
+ "uid": "c4e0-39"
90
90
  },
91
91
  {
92
- "uid": "b6e9-30"
92
+ "uid": "c4e0-34"
93
93
  }
94
94
  ],
95
95
  "importedBy": [],
96
96
  "isEntry": true
97
97
  },
98
- "b6e9-34": {
98
+ "c4e0-38": {
99
99
  "id": "react",
100
100
  "moduleParts": {},
101
101
  "imported": [],
102
102
  "importedBy": [
103
103
  {
104
- "uid": "b6e9-32"
104
+ "uid": "c4e0-36"
105
105
  }
106
106
  ],
107
107
  "isExternal": true
108
108
  },
109
- "b6e9-35": {
109
+ "c4e0-39": {
110
110
  "id": "use-sync-external-store/shim",
111
111
  "moduleParts": {},
112
112
  "imported": [],
113
113
  "importedBy": [
114
114
  {
115
- "uid": "b6e9-32"
115
+ "uid": "c4e0-36"
116
116
  }
117
117
  ],
118
118
  "isExternal": true
@@ -900,6 +900,15 @@
900
900
 
901
901
  return parsedPath;
902
902
  }
903
+ var prefix = 'Invariant failed';
904
+ function invariant(condition, message) {
905
+ if (condition) {
906
+ return;
907
+ }
908
+ var provided = typeof message === 'function' ? message() : message;
909
+ var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
910
+ throw new Error(value);
911
+ }
903
912
 
904
913
  // @ts-nocheck
905
914
  // We're inlining qss here for compression's sake, but we've included it as a hard dependency for the MIT license it requires.
@@ -954,7 +963,7 @@
954
963
  return out;
955
964
  }
956
965
 
957
- const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId) {
966
+ const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
958
967
  if (options === void 0) {
959
968
  options = {};
960
969
  }
@@ -965,8 +974,6 @@
965
974
 
966
975
  if (isRoot) {
967
976
  options.path = rootRouteId;
968
- } else {
969
- warning(!options.path, 'Routes must have a path property.');
970
977
  } // Strip the root from parentIds
971
978
 
972
979
 
@@ -974,13 +981,14 @@
974
981
  parentId = '';
975
982
  }
976
983
 
977
- let path = String(isRoot ? rootRouteId : options.path); // If the path is anything other than an index path, trim it up
984
+ let path = isRoot ? rootRouteId : options.path; // If the path is anything other than an index path, trim it up
978
985
 
979
- if (path !== '/') {
986
+ if (path && path !== '/') {
980
987
  path = trimPath(path);
981
988
  }
982
989
 
983
- let id = joinPaths([parentId, path]);
990
+ const routeId = path || options.id;
991
+ let id = joinPaths([parentId, routeId]);
984
992
 
985
993
  if (path === rootRouteId) {
986
994
  path = '/';
@@ -990,14 +998,15 @@
990
998
  id = joinPaths(['/', id]);
991
999
  }
992
1000
 
993
- const fullPath = id === rootRouteId ? '/' : trimPathRight(id);
1001
+ const fullPath = id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]));
994
1002
  return {
995
1003
  id: id,
1004
+ routeId: routeId,
996
1005
  path: path,
997
1006
  fullPath: fullPath,
998
1007
  options: options,
999
1008
  children,
1000
- addChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id)), false, parentId)
1009
+ addChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)), false, parentId, parentPath)
1001
1010
  };
1002
1011
  };
1003
1012
  const rootRouteId = '__root__';
@@ -1373,55 +1382,76 @@
1373
1382
 
1374
1383
  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 : [])];
1375
1384
 
1376
- const recurse = async (routes, parentMatch) => {
1377
- var _parentMatch$params, _router$options$filte, _router$preloadCache$, _route$childRoutes2;
1385
+ const recurse = async routes => {
1386
+ var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
1378
1387
 
1388
+ const parentMatch = last(matches);
1379
1389
  let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
1380
1390
  const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
1381
- const route = filteredRoutes == null ? void 0 : filteredRoutes.find(route => {
1382
- var _route$childRoutes, _route$options$caseSe;
1383
-
1384
- const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length);
1385
- const matchParams = matchPathname(pathname, {
1386
- to: route.fullPath,
1387
- fuzzy,
1388
- caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
1389
- });
1391
+ let foundRoutes = [];
1390
1392
 
1391
- if (matchParams) {
1392
- let parsedParams;
1393
+ const findMatchInRoutes = (parentRoutes, routes) => {
1394
+ routes.some(route => {
1395
+ var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
1393
1396
 
1394
- try {
1395
- var _route$options$parseP;
1397
+ if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
1398
+ return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
1399
+ }
1396
1400
 
1397
- parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
1398
- } catch (err) {
1399
- if (opts != null && opts.strictParseParams) {
1400
- throw err;
1401
+ const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
1402
+ const matchParams = matchPathname(pathname, {
1403
+ to: route.fullPath,
1404
+ fuzzy,
1405
+ caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
1406
+ });
1407
+
1408
+ if (matchParams) {
1409
+ let parsedParams;
1410
+
1411
+ try {
1412
+ var _route$options$parseP;
1413
+
1414
+ parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
1415
+ } catch (err) {
1416
+ if (opts != null && opts.strictParseParams) {
1417
+ throw err;
1418
+ }
1401
1419
  }
1420
+
1421
+ params = _extends$1({}, params, parsedParams);
1402
1422
  }
1403
1423
 
1404
- params = _extends$1({}, params, parsedParams);
1405
- }
1424
+ if (!!matchParams) {
1425
+ foundRoutes = [...parentRoutes, route];
1426
+ }
1406
1427
 
1407
- return !!matchParams;
1408
- });
1428
+ return !!foundRoutes.length;
1429
+ });
1430
+ return !!foundRoutes.length;
1431
+ };
1409
1432
 
1410
- if (!route) {
1433
+ findMatchInRoutes([], filteredRoutes);
1434
+
1435
+ if (!foundRoutes.length) {
1411
1436
  return;
1412
1437
  }
1413
1438
 
1414
- const interpolatedPath = interpolatePath(route.routePath, params);
1415
- const matchId = interpolatePath(route.routeId, params, true);
1416
- const match = existingMatches.find(d => d.matchId === matchId) || ((_router$preloadCache$ = router.preloadCache[matchId]) == null ? void 0 : _router$preloadCache$.match) || createRouteMatch(router, route, {
1417
- matchId,
1418
- params,
1419
- pathname: joinPaths([pathname, interpolatedPath])
1439
+ foundRoutes.forEach(foundRoute => {
1440
+ var _router$preloadCache$;
1441
+
1442
+ const interpolatedPath = interpolatePath(foundRoute.routePath, params);
1443
+ const matchId = interpolatePath(foundRoute.routeId, params, true);
1444
+ const match = existingMatches.find(d => d.matchId === matchId) || ((_router$preloadCache$ = router.preloadCache[matchId]) == null ? void 0 : _router$preloadCache$.match) || createRouteMatch(router, foundRoute, {
1445
+ matchId,
1446
+ params,
1447
+ pathname: joinPaths([pathname, interpolatedPath])
1448
+ });
1449
+ matches.push(match);
1420
1450
  });
1421
- matches.push(match);
1451
+ const foundRoute = last(foundRoutes);
1422
1452
 
1423
- if ((_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length) {
1424
- recurse(route.childRoutes, match);
1453
+ if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
1454
+ recurse(foundRoute.childRoutes);
1425
1455
  }
1426
1456
  };
1427
1457
 
@@ -1525,12 +1555,7 @@
1525
1555
  isExternal = true;
1526
1556
  } catch (e) {}
1527
1557
 
1528
- if (isExternal) {
1529
- {
1530
- throw new Error('Attempting to navigate to external url with router.navigate!');
1531
- }
1532
- }
1533
-
1558
+ invariant(!isExternal, 'Attempting to navigate to external url with router.navigate!');
1534
1559
  return router._navigate({
1535
1560
  from: fromString,
1536
1561
  to: toString,
@@ -1685,13 +1710,14 @@
1685
1710
  // ]).replace(new RegExp(`^${rootRouteId}`), '')
1686
1711
  // ) as TRouteInfo['id']
1687
1712
  const {
1688
- id: routeId,
1713
+ id,
1714
+ routeId,
1689
1715
  path: routePath,
1690
1716
  fullPath
1691
1717
  } = routeConfig;
1692
1718
 
1693
- const action = router.state.actions[routeId] || (() => {
1694
- router.state.actions[routeId] = {
1719
+ const action = router.state.actions[id] || (() => {
1720
+ router.state.actions[id] = {
1695
1721
  pending: [],
1696
1722
  submit: async (submission, actionOpts) => {
1697
1723
  var _actionOpts$invalidat;
@@ -1742,11 +1768,12 @@
1742
1768
  }
1743
1769
  }
1744
1770
  };
1745
- return router.state.actions[routeId];
1771
+ return router.state.actions[id];
1746
1772
  })();
1747
1773
 
1748
1774
  let route = {
1749
- routeId,
1775
+ routeId: id,
1776
+ routeRouteId: routeId,
1750
1777
  routePath,
1751
1778
  fullPath,
1752
1779
  options,
@@ -2483,34 +2510,21 @@
2483
2510
  useRoute: routeId => {
2484
2511
  const route = router.getRoute(routeId);
2485
2512
  useRouterSubscription(router);
2486
-
2487
- if (!route) {
2488
- throw new Error("Could not find a route for route \"" + routeId + "\"! Did you forget to add it to your route config?");
2489
- }
2490
-
2513
+ invariant(route, "Could not find a route for route \"" + routeId + "\"! Did you forget to add it to your route config?");
2491
2514
  return route;
2492
2515
  },
2493
2516
  useMatch: routeId => {
2494
- if (routeId === rootRouteId) {
2495
- throw new Error("\"" + rootRouteId + "\" cannot be used with useMatch! Did you mean to useRoute(\"" + rootRouteId + "\")?");
2496
- }
2517
+ invariant(routeId !== rootRouteId, "\"" + rootRouteId + "\" cannot be used with useMatch! Did you mean to useRoute(\"" + rootRouteId + "\")?");
2497
2518
 
2498
2519
  const runtimeMatch = _useMatch();
2499
2520
 
2500
2521
  const match = router.state.matches.find(d => d.routeId === routeId);
2501
-
2502
- if (!match) {
2503
- throw new Error("Could not find a match for route \"" + routeId + "\" being rendered in this component!");
2504
- }
2505
-
2506
- if (runtimeMatch.routeId !== (match == null ? void 0 : match.routeId)) {
2507
- 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?");
2508
- }
2509
-
2522
+ invariant(match, "Could not find a match for route \"" + routeId + "\" being rendered in this component!");
2523
+ 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?");
2510
2524
  useRouterSubscription(router);
2511
2525
 
2512
2526
  if (!match) {
2513
- throw new Error('Match not found!');
2527
+ invariant('Match not found!');
2514
2528
  }
2515
2529
 
2516
2530
  return match;
@@ -2721,6 +2735,7 @@
2721
2735
  exports.defaultParseSearch = defaultParseSearch;
2722
2736
  exports.defaultStringifySearch = defaultStringifySearch;
2723
2737
  exports.functionalUpdate = functionalUpdate;
2738
+ exports.invariant = invariant;
2724
2739
  exports.last = last;
2725
2740
  exports.matchByPath = matchByPath;
2726
2741
  exports.matchPathname = matchPathname;