@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.
@@ -839,6 +839,16 @@
839
839
  return parsedPath;
840
840
  }
841
841
 
842
+ var prefix = 'Invariant failed';
843
+ function invariant(condition, message) {
844
+ if (condition) {
845
+ return;
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
+
842
852
  // @ts-nocheck
843
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.
844
854
  function encode(obj, pfx) {
@@ -892,7 +902,7 @@
892
902
  return out;
893
903
  }
894
904
 
895
- const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId) {
905
+ const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
896
906
  if (options === void 0) {
897
907
  options = {};
898
908
  }
@@ -903,8 +913,6 @@
903
913
 
904
914
  if (isRoot) {
905
915
  options.path = rootRouteId;
906
- } else {
907
- warning(!options.path, 'Routes must have a path property.');
908
916
  } // Strip the root from parentIds
909
917
 
910
918
 
@@ -912,13 +920,14 @@
912
920
  parentId = '';
913
921
  }
914
922
 
915
- let path = String(isRoot ? rootRouteId : options.path); // If the path is anything other than an index path, trim it up
923
+ let path = isRoot ? rootRouteId : options.path; // If the path is anything other than an index path, trim it up
916
924
 
917
- if (path !== '/') {
925
+ if (path && path !== '/') {
918
926
  path = trimPath(path);
919
927
  }
920
928
 
921
- let id = joinPaths([parentId, path]);
929
+ const routeId = path || options.id;
930
+ let id = joinPaths([parentId, routeId]);
922
931
 
923
932
  if (path === rootRouteId) {
924
933
  path = '/';
@@ -928,14 +937,15 @@
928
937
  id = joinPaths(['/', id]);
929
938
  }
930
939
 
931
- const fullPath = id === rootRouteId ? '/' : trimPathRight(id);
940
+ const fullPath = id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]));
932
941
  return {
933
942
  id: id,
943
+ routeId: routeId,
934
944
  path: path,
935
945
  fullPath: fullPath,
936
946
  options: options,
937
947
  children,
938
- 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)
939
949
  };
940
950
  };
941
951
  const rootRouteId = '__root__';
@@ -1311,55 +1321,76 @@
1311
1321
 
1312
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 : [])];
1313
1323
 
1314
- const recurse = async (routes, parentMatch) => {
1315
- var _parentMatch$params, _router$options$filte, _router$preloadCache$, _route$childRoutes2;
1324
+ const recurse = async routes => {
1325
+ var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
1316
1326
 
1327
+ const parentMatch = last(matches);
1317
1328
  let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
1318
1329
  const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
1319
- const route = filteredRoutes == null ? void 0 : filteredRoutes.find(route => {
1320
- var _route$childRoutes, _route$options$caseSe;
1321
-
1322
- const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length);
1323
- const matchParams = matchPathname(pathname, {
1324
- to: route.fullPath,
1325
- fuzzy,
1326
- caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
1327
- });
1330
+ let foundRoutes = [];
1328
1331
 
1329
- if (matchParams) {
1330
- let parsedParams;
1332
+ const findMatchInRoutes = (parentRoutes, routes) => {
1333
+ routes.some(route => {
1334
+ var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
1331
1335
 
1332
- try {
1333
- var _route$options$parseP;
1336
+ if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
1337
+ return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
1338
+ }
1334
1339
 
1335
- parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
1336
- } catch (err) {
1337
- if (opts != null && opts.strictParseParams) {
1338
- throw err;
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
+ }
1339
1358
  }
1359
+
1360
+ params = _extends$1({}, params, parsedParams);
1340
1361
  }
1341
1362
 
1342
- params = _extends$1({}, params, parsedParams);
1343
- }
1363
+ if (!!matchParams) {
1364
+ foundRoutes = [...parentRoutes, route];
1365
+ }
1344
1366
 
1345
- return !!matchParams;
1346
- });
1367
+ return !!foundRoutes.length;
1368
+ });
1369
+ return !!foundRoutes.length;
1370
+ };
1347
1371
 
1348
- if (!route) {
1372
+ findMatchInRoutes([], filteredRoutes);
1373
+
1374
+ if (!foundRoutes.length) {
1349
1375
  return;
1350
1376
  }
1351
1377
 
1352
- const interpolatedPath = interpolatePath(route.routePath, params);
1353
- const matchId = interpolatePath(route.routeId, params, true);
1354
- const match = existingMatches.find(d => d.matchId === matchId) || ((_router$preloadCache$ = router.preloadCache[matchId]) == null ? void 0 : _router$preloadCache$.match) || createRouteMatch(router, route, {
1355
- matchId,
1356
- params,
1357
- pathname: joinPaths([pathname, interpolatedPath])
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);
1358
1389
  });
1359
- matches.push(match);
1390
+ const foundRoute = last(foundRoutes);
1360
1391
 
1361
- if ((_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length) {
1362
- recurse(route.childRoutes, match);
1392
+ if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
1393
+ recurse(foundRoute.childRoutes);
1363
1394
  }
1364
1395
  };
1365
1396
 
@@ -1463,12 +1494,7 @@
1463
1494
  isExternal = true;
1464
1495
  } catch (e) {}
1465
1496
 
1466
- if (isExternal) {
1467
- {
1468
- throw new Error('Attempting to navigate to external url with router.navigate!');
1469
- }
1470
- }
1471
-
1497
+ invariant(!isExternal, 'Attempting to navigate to external url with router.navigate!');
1472
1498
  return router._navigate({
1473
1499
  from: fromString,
1474
1500
  to: toString,
@@ -1623,13 +1649,14 @@
1623
1649
  // ]).replace(new RegExp(`^${rootRouteId}`), '')
1624
1650
  // ) as TRouteInfo['id']
1625
1651
  const {
1626
- id: routeId,
1652
+ id,
1653
+ routeId,
1627
1654
  path: routePath,
1628
1655
  fullPath
1629
1656
  } = routeConfig;
1630
1657
 
1631
- const action = router.state.actions[routeId] || (() => {
1632
- router.state.actions[routeId] = {
1658
+ const action = router.state.actions[id] || (() => {
1659
+ router.state.actions[id] = {
1633
1660
  pending: [],
1634
1661
  submit: async (submission, actionOpts) => {
1635
1662
  var _actionOpts$invalidat;
@@ -1680,11 +1707,12 @@
1680
1707
  }
1681
1708
  }
1682
1709
  };
1683
- return router.state.actions[routeId];
1710
+ return router.state.actions[id];
1684
1711
  })();
1685
1712
 
1686
1713
  let route = {
1687
- routeId,
1714
+ routeId: id,
1715
+ routeRouteId: routeId,
1688
1716
  routePath,
1689
1717
  fullPath,
1690
1718
  options,
@@ -2305,6 +2333,7 @@
2305
2333
  exports.defaultParseSearch = defaultParseSearch;
2306
2334
  exports.defaultStringifySearch = defaultStringifySearch;
2307
2335
  exports.functionalUpdate = functionalUpdate;
2336
+ exports.invariant = invariant;
2308
2337
  exports.last = last;
2309
2338
  exports.matchByPath = matchByPath;
2310
2339
  exports.matchPathname = matchPathname;