@tanstack/react-router 0.0.1-beta.209 → 0.0.1-beta.210

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.
Files changed (72) hide show
  1. package/build/cjs/CatchBoundary.js +125 -0
  2. package/build/cjs/CatchBoundary.js.map +1 -0
  3. package/build/cjs/Matches.js +223 -0
  4. package/build/cjs/Matches.js.map +1 -0
  5. package/build/cjs/RouterProvider.js +99 -53
  6. package/build/cjs/RouterProvider.js.map +1 -1
  7. package/build/cjs/index.js +46 -37
  8. package/build/cjs/index.js.map +1 -1
  9. package/build/cjs/lazyRouteComponent.js +57 -0
  10. package/build/cjs/lazyRouteComponent.js.map +1 -0
  11. package/build/cjs/link.js +150 -0
  12. package/build/cjs/link.js.map +1 -0
  13. package/build/cjs/route.js +9 -5
  14. package/build/cjs/route.js.map +1 -1
  15. package/build/cjs/router.js.map +1 -1
  16. package/build/cjs/searchParams.js.map +1 -1
  17. package/build/cjs/useBlocker.js +64 -0
  18. package/build/cjs/useBlocker.js.map +1 -0
  19. package/build/cjs/useNavigate.js +78 -0
  20. package/build/cjs/useNavigate.js.map +1 -0
  21. package/build/cjs/useParams.js +28 -0
  22. package/build/cjs/useParams.js.map +1 -0
  23. package/build/cjs/useSearch.js +27 -0
  24. package/build/cjs/useSearch.js.map +1 -0
  25. package/build/cjs/utils.js +30 -1
  26. package/build/cjs/utils.js.map +1 -1
  27. package/build/esm/index.js +491 -514
  28. package/build/esm/index.js.map +1 -1
  29. package/build/stats-html.html +1 -1
  30. package/build/stats-react.json +484 -208
  31. package/build/types/CatchBoundary.d.ts +33 -0
  32. package/build/types/Matches.d.ts +31 -0
  33. package/build/types/RouterProvider.d.ts +42 -18
  34. package/build/types/fileRoute.d.ts +7 -7
  35. package/build/types/index.d.ts +13 -7
  36. package/build/types/injectHtml.d.ts +0 -0
  37. package/build/types/lazyRouteComponent.d.ts +2 -0
  38. package/build/types/link.d.ts +10 -3
  39. package/build/types/route.d.ts +39 -7
  40. package/build/types/router.d.ts +6 -7
  41. package/build/types/useBlocker.d.ts +8 -0
  42. package/build/types/useNavigate.d.ts +20 -0
  43. package/build/types/useParams.d.ts +7 -0
  44. package/build/types/useSearch.d.ts +7 -0
  45. package/build/types/utils.d.ts +17 -0
  46. package/build/umd/index.development.js +492 -513
  47. package/build/umd/index.development.js.map +1 -1
  48. package/build/umd/index.production.js +1 -1
  49. package/build/umd/index.production.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/CatchBoundary.tsx +97 -0
  52. package/src/Matches.tsx +315 -0
  53. package/src/RouterProvider.tsx +317 -251
  54. package/src/index.tsx +17 -8
  55. package/src/injectHtml.ts +28 -0
  56. package/src/lazyRouteComponent.tsx +33 -0
  57. package/src/{link.ts → link.tsx} +163 -3
  58. package/src/location.ts +1 -0
  59. package/src/route.ts +86 -16
  60. package/src/router.ts +6 -7
  61. package/src/searchParams.ts +1 -0
  62. package/src/useBlocker.tsx +34 -0
  63. package/src/useNavigate.tsx +109 -0
  64. package/src/useParams.tsx +25 -0
  65. package/src/useSearch.tsx +25 -0
  66. package/src/utils.ts +83 -3
  67. package/build/cjs/react.js +0 -620
  68. package/build/cjs/react.js.map +0 -1
  69. package/build/types/RouteMatch.d.ts +0 -23
  70. package/build/types/react.d.ts +0 -141
  71. package/src/RouteMatch.ts +0 -28
  72. package/src/react.tsx +0 -1013
@@ -341,6 +341,91 @@
341
341
  }
342
342
  }
343
343
 
344
+ function CatchBoundary(props) {
345
+ const errorComponent = props.errorComponent ?? ErrorComponent;
346
+ return /*#__PURE__*/React__namespace.createElement(CatchBoundaryImpl, {
347
+ resetKey: props.resetKey,
348
+ onCatch: props.onCatch,
349
+ children: ({
350
+ error
351
+ }) => {
352
+ if (error) {
353
+ return /*#__PURE__*/React__namespace.createElement(errorComponent, {
354
+ error
355
+ });
356
+ }
357
+ return props.children;
358
+ }
359
+ });
360
+ }
361
+ class CatchBoundaryImpl extends React__namespace.Component {
362
+ state = {
363
+ error: null
364
+ };
365
+ static getDerivedStateFromError(error) {
366
+ return {
367
+ error
368
+ };
369
+ }
370
+ componentDidUpdate(prevProps, prevState) {
371
+ if (prevState.error && prevProps.resetKey !== this.props.resetKey) {
372
+ this.setState({
373
+ error: null
374
+ });
375
+ }
376
+ }
377
+ componentDidCatch(error) {
378
+ this.props.onCatch?.(error);
379
+ }
380
+ render() {
381
+ return this.props.children(this.state);
382
+ }
383
+ }
384
+ function ErrorComponent({
385
+ error
386
+ }) {
387
+ const [show, setShow] = React__namespace.useState("development" !== 'production');
388
+ return /*#__PURE__*/React__namespace.createElement("div", {
389
+ style: {
390
+ padding: '.5rem',
391
+ maxWidth: '100%'
392
+ }
393
+ }, /*#__PURE__*/React__namespace.createElement("div", {
394
+ style: {
395
+ display: 'flex',
396
+ alignItems: 'center',
397
+ gap: '.5rem'
398
+ }
399
+ }, /*#__PURE__*/React__namespace.createElement("strong", {
400
+ style: {
401
+ fontSize: '1rem'
402
+ }
403
+ }, "Something went wrong!"), /*#__PURE__*/React__namespace.createElement("button", {
404
+ style: {
405
+ appearance: 'none',
406
+ fontSize: '.6em',
407
+ border: '1px solid currentColor',
408
+ padding: '.1rem .2rem',
409
+ fontWeight: 'bold',
410
+ borderRadius: '.25rem'
411
+ },
412
+ onClick: () => setShow(d => !d)
413
+ }, show ? 'Hide Error' : 'Show Error')), /*#__PURE__*/React__namespace.createElement("div", {
414
+ style: {
415
+ height: '.25rem'
416
+ }
417
+ }), show ? /*#__PURE__*/React__namespace.createElement("div", null, /*#__PURE__*/React__namespace.createElement("pre", {
418
+ style: {
419
+ fontSize: '.7em',
420
+ border: '1px solid red',
421
+ borderRadius: '.25rem',
422
+ padding: '.3rem',
423
+ color: 'red',
424
+ overflow: 'auto'
425
+ }
426
+ }, error.message ? /*#__PURE__*/React__namespace.createElement("code", null, error.message) : null)) : null);
427
+ }
428
+
344
429
  // export type Expand<T> = T
345
430
 
346
431
  // type Compute<T> = { [K in keyof T]: T[K] } | never
@@ -481,7 +566,7 @@
481
566
  return !Object.keys(b).some(key => !partialDeepEqual(a[key], b[key]));
482
567
  }
483
568
  if (Array.isArray(a) && Array.isArray(b)) {
484
- return a.length === b.length && a.every((item, index) => partialDeepEqual(item, b[index]));
569
+ return !(a.length !== b.length || a.some((item, index) => !partialDeepEqual(item, b[index])));
485
570
  }
486
571
  return false;
487
572
  }
@@ -491,6 +576,31 @@
491
576
  const ref = React__namespace.useRef((...args) => fnRef.current(...args));
492
577
  return ref.current;
493
578
  }
579
+ function shallow(objA, objB) {
580
+ if (Object.is(objA, objB)) {
581
+ return true;
582
+ }
583
+ if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
584
+ return false;
585
+ }
586
+ const keysA = Object.keys(objA);
587
+ if (keysA.length !== Object.keys(objB).length) {
588
+ return false;
589
+ }
590
+ for (let i = 0; i < keysA.length; i++) {
591
+ if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
592
+ return false;
593
+ }
594
+ }
595
+ return true;
596
+ }
597
+ function useRouteContext(opts) {
598
+ return useMatch({
599
+ ...opts,
600
+ select: match => opts?.select ? opts.select(match.context) : match.context
601
+ });
602
+ }
603
+ const useLayoutEffect = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
494
604
 
495
605
  function joinPaths(paths) {
496
606
  return cleanPath(paths.filter(Boolean).join('/'));
@@ -676,6 +786,16 @@
676
786
  return isMatch ? params : undefined;
677
787
  }
678
788
 
789
+ // Detect if we're in the DOM
790
+
791
+ function redirect(opts) {
792
+ opts.isRedirect = true;
793
+ return opts;
794
+ }
795
+ function isRedirect(obj) {
796
+ return !!obj?.isRedirect;
797
+ }
798
+
679
799
  // @ts-nocheck
680
800
 
681
801
  // qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.
@@ -724,21 +844,6 @@
724
844
  return out;
725
845
  }
726
846
 
727
- function _extends() {
728
- _extends = Object.assign ? Object.assign.bind() : function (target) {
729
- for (var i = 1; i < arguments.length; i++) {
730
- var source = arguments[i];
731
- for (var key in source) {
732
- if (Object.prototype.hasOwnProperty.call(source, key)) {
733
- target[key] = source[key];
734
- }
735
- }
736
- }
737
- return target;
738
- };
739
- return _extends.apply(this, arguments);
740
- }
741
-
742
847
  const defaultParseSearch = parseSearchWith(JSON.parse);
743
848
  const defaultStringifySearch = stringifySearchWith(JSON.stringify, JSON.parse);
744
849
  function parseSearchWith(parser) {
@@ -984,26 +1089,20 @@
984
1089
  };
985
1090
  }
986
1091
 
987
- // Detect if we're in the DOM
988
-
989
- function redirect(opts) {
990
- opts.isRedirect = true;
991
- return opts;
992
- }
993
- function isRedirect(obj) {
994
- return !!obj?.isRedirect;
995
- }
996
-
997
- const preloadWarning = 'Error preloading route! ☝️';
998
1092
  const routerContext = /*#__PURE__*/React__namespace.createContext(null);
999
1093
  if (typeof document !== 'undefined') {
1000
1094
  window.__TSR_ROUTER_CONTEXT__ = routerContext;
1001
1095
  }
1096
+ const preloadWarning = 'Error preloading route! ☝️';
1097
+ function isCtrlEvent(e) {
1098
+ return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
1099
+ }
1100
+ class SearchParamError extends Error {}
1101
+ class PathParamError extends Error {}
1002
1102
  function getInitialRouterState(location) {
1003
1103
  return {
1004
1104
  status: 'idle',
1005
- isFetching: false,
1006
- resolvedLocation: location,
1105
+ resolvedLocation: undefined,
1007
1106
  location: location,
1008
1107
  matches: [],
1009
1108
  pendingMatches: [],
@@ -1064,7 +1163,20 @@
1064
1163
  }
1065
1164
  return location;
1066
1165
  });
1067
- const [state, setState] = React__namespace.useState(() => getInitialRouterState(parseLocation()));
1166
+ const [preState, setState] = React__namespace.useState(() => getInitialRouterState(parseLocation()));
1167
+ const [isTransitioning, startReactTransition] = React__namespace.useTransition();
1168
+ const state = React__namespace.useMemo(() => ({
1169
+ ...preState,
1170
+ status: isTransitioning ? 'pending' : 'idle'
1171
+ }), [preState, isTransitioning]);
1172
+ React__namespace.useLayoutEffect(() => {
1173
+ if (!isTransitioning && state.resolvedLocation !== state.location) {
1174
+ setState(s => ({
1175
+ ...s,
1176
+ resolvedLocation: s.location
1177
+ }));
1178
+ }
1179
+ });
1068
1180
  const basepath = `/${trimPath(options.basepath ?? '') ?? ''}`;
1069
1181
  const resolvePathWithBase = useStableCallback((from, path) => {
1070
1182
  return resolvePath(basepath, from, cleanPath(path));
@@ -1283,7 +1395,7 @@
1283
1395
  cancelMatch(match.id);
1284
1396
  });
1285
1397
  });
1286
- const buildLocation = useStableCallback((opts = {}) => {
1398
+ const buildLocation = useStableCallback(opts => {
1287
1399
  const build = (dest = {}, matches) => {
1288
1400
  const from = latestLocationRef.current;
1289
1401
  const fromPathname = dest.from ?? from.pathname;
@@ -1376,7 +1488,10 @@
1376
1488
  }
1377
1489
  return buildWithMatches(opts);
1378
1490
  });
1379
- const commitLocation = useStableCallback(async next => {
1491
+ const commitLocation = useStableCallback(async ({
1492
+ startTransition,
1493
+ ...next
1494
+ }) => {
1380
1495
  if (navigateTimeoutRef.current) clearTimeout(navigateTimeoutRef.current);
1381
1496
  const isSameUrl = latestLocationRef.current.href === next.href;
1382
1497
 
@@ -1409,7 +1524,14 @@
1409
1524
  nextHistory.state.__tempKey = tempLocationKeyRef.current;
1410
1525
  }
1411
1526
  }
1412
- history[next.replace ? 'replace' : 'push'](nextHistory.href, nextHistory.state);
1527
+ const apply = () => {
1528
+ history[next.replace ? 'replace' : 'push'](nextHistory.href, nextHistory.state);
1529
+ };
1530
+ if (startTransition ?? true) {
1531
+ startReactTransition(apply);
1532
+ } else {
1533
+ apply();
1534
+ }
1413
1535
  }
1414
1536
  resetNextScrollRef.current = next.resetScroll ?? true;
1415
1537
  return latestLoadPromiseRef.current;
@@ -1417,11 +1539,13 @@
1417
1539
  const buildAndCommitLocation = useStableCallback(({
1418
1540
  replace,
1419
1541
  resetScroll,
1542
+ startTransition,
1420
1543
  ...rest
1421
1544
  } = {}) => {
1422
1545
  const location = buildLocation(rest);
1423
1546
  return commitLocation({
1424
1547
  ...location,
1548
+ startTransition,
1425
1549
  replace,
1426
1550
  resetScroll
1427
1551
  });
@@ -1503,7 +1627,8 @@
1503
1627
  navigate: opts => navigate({
1504
1628
  ...opts,
1505
1629
  from: match.pathname
1506
- })
1630
+ }),
1631
+ buildLocation
1507
1632
  })) ?? {};
1508
1633
  const context = {
1509
1634
  ...parentContext,
@@ -1564,7 +1689,7 @@
1564
1689
  from: match.pathname
1565
1690
  })
1566
1691
  });
1567
- await Promise.all([componentsPromise, loaderPromise]);
1692
+ const [_, loaderContext] = await Promise.all([componentsPromise, loaderPromise]);
1568
1693
  if (latestPromise = checkLatest()) return await latestPromise;
1569
1694
  matches[index] = match = {
1570
1695
  ...match,
@@ -1618,7 +1743,7 @@
1618
1743
  const load = useStableCallback(async () => {
1619
1744
  const promise = new Promise(async (resolve, reject) => {
1620
1745
  const next = latestLocationRef.current;
1621
- const prevLocation = state.resolvedLocation;
1746
+ const prevLocation = state.resolvedLocation || state.location;
1622
1747
  const pathDidChange = !!(next && prevLocation.href !== next.href);
1623
1748
  let latestPromise;
1624
1749
 
@@ -1631,19 +1756,14 @@
1631
1756
  pathChanged: pathDidChange
1632
1757
  });
1633
1758
 
1634
- // Ingest the new location
1635
- setState(s => ({
1636
- ...s,
1637
- location: next
1638
- }));
1639
-
1640
1759
  // Match the routes
1641
1760
  let matches = matchRoutes(next.pathname, next.search, {
1642
1761
  debug: true
1643
1762
  });
1763
+
1764
+ // Ingest the new matches
1644
1765
  setState(s => ({
1645
1766
  ...s,
1646
- status: 'pending',
1647
1767
  matches
1648
1768
  }));
1649
1769
  try {
@@ -1674,11 +1794,11 @@
1674
1794
  // state.pendingMatches.includes(id),
1675
1795
  // )
1676
1796
 
1677
- setState(s => ({
1678
- ...s,
1679
- status: 'idle',
1680
- resolvedLocation: s.location
1681
- }));
1797
+ // setState((s) => ({
1798
+ // ...s,
1799
+ // status: 'idle',
1800
+ // resolvedLocation: s.location,
1801
+ // }))
1682
1802
 
1683
1803
  // TODO:
1684
1804
  // ;(
@@ -1723,7 +1843,7 @@
1723
1843
  });
1724
1844
  return [last(matches), matches];
1725
1845
  });
1726
- const buildLink = useStableCallback((state, dest) => {
1846
+ const buildLink = useStableCallback(dest => {
1727
1847
  // If this link simply reloads the current route,
1728
1848
  // make sure it has a new key so it will trigger a data refresh
1729
1849
 
@@ -1738,7 +1858,8 @@
1738
1858
  disabled,
1739
1859
  target,
1740
1860
  replace,
1741
- resetScroll
1861
+ resetScroll,
1862
+ startTransition
1742
1863
  } = dest;
1743
1864
  try {
1744
1865
  new URL(`${to}`);
@@ -1773,7 +1894,8 @@
1773
1894
  commitLocation({
1774
1895
  ...next,
1775
1896
  replace,
1776
- resetScroll
1897
+ resetScroll,
1898
+ startTransition
1777
1899
  });
1778
1900
  }
1779
1901
  };
@@ -1831,15 +1953,17 @@
1831
1953
  React__namespace.useLayoutEffect(() => {
1832
1954
  const unsub = history.subscribe(() => {
1833
1955
  latestLocationRef.current = parseLocation(latestLocationRef.current);
1834
- React__namespace.startTransition(() => {
1835
- if (state.location !== latestLocationRef.current) {
1836
- try {
1837
- load();
1838
- } catch (err) {
1839
- console.error(err);
1840
- }
1956
+ setState(s => ({
1957
+ ...s,
1958
+ status: 'pending'
1959
+ }));
1960
+ if (state.location !== latestLocationRef.current) {
1961
+ try {
1962
+ load();
1963
+ } catch (err) {
1964
+ console.error(err);
1841
1965
  }
1842
- });
1966
+ }
1843
1967
  });
1844
1968
  const nextLocation = buildLocation({
1845
1969
  search: true,
@@ -1860,14 +1984,15 @@
1860
1984
  const initialLoad = React__namespace.useRef(true);
1861
1985
  if (initialLoad.current) {
1862
1986
  initialLoad.current = false;
1863
- try {
1864
- load();
1865
- } catch (err) {
1866
- console.error(err);
1867
- }
1987
+ startReactTransition(() => {
1988
+ try {
1989
+ load();
1990
+ } catch (err) {
1991
+ console.error(err);
1992
+ }
1993
+ });
1868
1994
  }
1869
- React__namespace.useMemo(() => [...state.matches, ...state.pendingMatches].some(d => d.isFetching), [state.matches, state.pendingMatches]);
1870
- const matchRoute = useStableCallback((state, location, opts) => {
1995
+ const matchRoute = useStableCallback((location, opts) => {
1871
1996
  location = {
1872
1997
  ...location,
1873
1998
  to: location.to ? resolvePathWithBase(location.from || '', location.to) : undefined
@@ -1877,6 +2002,9 @@
1877
2002
  return false;
1878
2003
  }
1879
2004
  const baseLocation = opts?.pending ? latestLocationRef.current : state.resolvedLocation;
2005
+
2006
+ // const baseLocation = state.resolvedLocation
2007
+
1880
2008
  if (!baseLocation) {
1881
2009
  return false;
1882
2010
  }
@@ -1887,7 +2015,7 @@
1887
2015
  if (!match) {
1888
2016
  return false;
1889
2017
  }
1890
- if (opts?.includeSearch ?? true) {
2018
+ if (match && (opts?.includeSearch ?? true)) {
1891
2019
  return partialDeepEqual(baseLocation.search, next.search) ? match : false;
1892
2020
  }
1893
2021
  return match;
@@ -1901,292 +2029,39 @@
1901
2029
  routesById,
1902
2030
  options,
1903
2031
  history,
1904
- load
2032
+ load,
2033
+ buildLocation
1905
2034
  };
1906
2035
  return /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
1907
2036
  value: routerContextValue
1908
2037
  }, /*#__PURE__*/React__namespace.createElement(Matches, null));
1909
2038
  }
1910
- function isCtrlEvent(e) {
1911
- return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
1912
- }
1913
- class SearchParamError extends Error {}
1914
- class PathParamError extends Error {}
1915
2039
  function getRouteMatch(state, id) {
1916
2040
  return [...state.pendingMatches, ...state.matches].find(d => d.id === id);
1917
2041
  }
1918
-
1919
- const useLayoutEffect = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
1920
-
1921
- //
1922
-
1923
- function lazyRouteComponent(importer, exportName) {
1924
- let loadPromise;
1925
- const load = () => {
1926
- if (!loadPromise) {
1927
- loadPromise = importer();
1928
- }
1929
- return loadPromise;
1930
- };
1931
- const lazyComp = /*#__PURE__*/React__namespace.lazy(async () => {
1932
- const moduleExports = await load();
1933
- const comp = moduleExports[exportName ?? 'default'];
1934
- return {
1935
- default: comp
1936
- };
1937
- });
1938
- lazyComp.preload = load;
1939
- return lazyComp;
2042
+ function useRouterState(opts) {
2043
+ const {
2044
+ state
2045
+ } = useRouter();
2046
+ // return useStore(router.__store, opts?.select as any)
2047
+ return opts?.select ? opts.select(state) : state;
2048
+ }
2049
+ function useRouter() {
2050
+ const resolvedContext = window.__TSR_ROUTER_CONTEXT__ || routerContext;
2051
+ const value = React__namespace.useContext(resolvedContext);
2052
+ warning(value, 'useRouter must be used inside a <RouterProvider> component!');
2053
+ return value;
1940
2054
  }
1941
- //
1942
2055
 
1943
- function useLinkProps(options) {
2056
+ function Matches() {
1944
2057
  const {
1945
- buildLink,
1946
- state: routerState
2058
+ routesById,
2059
+ state
1947
2060
  } = useRouter();
1948
- const match = useMatch({
1949
- strict: false
1950
- });
1951
- const {
1952
- // custom props
1953
- type,
1954
- children,
1955
- target,
1956
- activeProps = () => ({
1957
- className: 'active'
1958
- }),
1959
- inactiveProps = () => ({}),
1960
- activeOptions,
1961
- disabled,
1962
- hash,
1963
- search,
1964
- params,
1965
- to,
1966
- state,
1967
- mask,
1968
- preload,
1969
- preloadDelay,
1970
- replace,
1971
- // element props
1972
- style,
1973
- className,
1974
- onClick,
1975
- onFocus,
1976
- onMouseEnter,
1977
- onMouseLeave,
1978
- onTouchStart,
1979
- ...rest
1980
- } = options;
1981
- const linkInfo = buildLink(routerState, {
1982
- from: options.to ? match.pathname : undefined,
1983
- ...options
1984
- });
1985
- if (linkInfo.type === 'external') {
1986
- const {
1987
- href
1988
- } = linkInfo;
1989
- return {
1990
- href
1991
- };
1992
- }
1993
- const {
1994
- handleClick,
1995
- handleFocus,
1996
- handleEnter,
1997
- handleLeave,
1998
- handleTouchStart,
1999
- isActive,
2000
- next
2001
- } = linkInfo;
2002
- const handleReactClick = e => {
2003
- if (options.startTransition ?? true) {
2004
- (React__namespace.startTransition || (d => d))(() => {
2005
- handleClick(e);
2006
- });
2007
- }
2008
- };
2009
- const composeHandlers = handlers => e => {
2010
- if (e.persist) e.persist();
2011
- handlers.filter(Boolean).forEach(handler => {
2012
- if (e.defaultPrevented) return;
2013
- handler(e);
2014
- });
2015
- };
2016
-
2017
- // Get the active props
2018
- const resolvedActiveProps = isActive ? functionalUpdate(activeProps, {}) ?? {} : {};
2019
-
2020
- // Get the inactive props
2021
- const resolvedInactiveProps = isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {};
2022
- return {
2023
- ...resolvedActiveProps,
2024
- ...resolvedInactiveProps,
2025
- ...rest,
2026
- href: disabled ? undefined : next.maskedLocation ? next.maskedLocation.href : next.href,
2027
- onClick: composeHandlers([onClick, handleReactClick]),
2028
- onFocus: composeHandlers([onFocus, handleFocus]),
2029
- onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),
2030
- onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),
2031
- onTouchStart: composeHandlers([onTouchStart, handleTouchStart]),
2032
- target,
2033
- style: {
2034
- ...style,
2035
- ...resolvedActiveProps.style,
2036
- ...resolvedInactiveProps.style
2037
- },
2038
- className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined,
2039
- ...(disabled ? {
2040
- role: 'link',
2041
- 'aria-disabled': true
2042
- } : undefined),
2043
- ['data-status']: isActive ? 'active' : undefined
2044
- };
2045
- }
2046
- const Link = /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
2047
- const linkProps = useLinkProps(props);
2048
- return /*#__PURE__*/React__namespace.createElement("a", _extends({
2049
- ref: ref
2050
- }, linkProps, {
2051
- children: typeof props.children === 'function' ? props.children({
2052
- isActive: linkProps['data-status'] === 'active'
2053
- }) : props.children
2054
- }));
2055
- });
2056
- function Navigate(props) {
2057
- const {
2058
- navigate
2059
- } = useRouter();
2060
- const match = useMatch({
2061
- strict: false
2062
- });
2063
- useLayoutEffect(() => {
2064
- navigate({
2065
- from: props.to ? match.pathname : undefined,
2066
- ...props
2067
- });
2068
- }, []);
2069
- return null;
2070
- }
2071
- const matchesContext = /*#__PURE__*/React__namespace.createContext(null);
2072
- function useRouter() {
2073
- const resolvedContext = window.__TSR_ROUTER_CONTEXT__ || routerContext;
2074
- const value = React__namespace.useContext(resolvedContext);
2075
- warning(value, 'useRouter must be used inside a <RouterProvider> component!');
2076
- return value;
2077
- }
2078
- function useRouterState(opts) {
2079
- const {
2080
- state
2081
- } = useRouter();
2082
- // return useStore(router.__store, opts?.select as any)
2083
- return opts?.select ? opts.select(state) : state;
2084
- }
2085
- function useMatches(opts) {
2086
- const contextMatches = React__namespace.useContext(matchesContext);
2087
- return useRouterState({
2088
- select: state => {
2089
- const matches = state.matches.slice(state.matches.findIndex(d => d.id === contextMatches[0]?.id));
2090
- return opts?.select ? opts.select(matches) : matches;
2091
- }
2092
- });
2093
- }
2094
- function useMatch(opts) {
2095
- const nearestMatch = React__namespace.useContext(matchesContext)[0];
2096
- const nearestMatchRouteId = nearestMatch?.routeId;
2097
- const matchRouteId = useRouterState({
2098
- select: state => {
2099
- const match = opts?.from ? state.matches.find(d => d.routeId === opts?.from) : state.matches.find(d => d.id === nearestMatch.id);
2100
- return match.routeId;
2101
- }
2102
- });
2103
- if (opts?.strict ?? true) {
2104
- invariant(nearestMatchRouteId == matchRouteId, `useMatch("${matchRouteId}") is being called in a component that is meant to render the '${nearestMatchRouteId}' route. Did you mean to 'useMatch("${matchRouteId}", { strict: false })' or 'useRoute("${matchRouteId}")' instead?`);
2105
- }
2106
- const matchSelection = useRouterState({
2107
- select: state => {
2108
- const match = opts?.from ? state.matches.find(d => d.routeId === opts?.from) : state.matches.find(d => d.id === nearestMatch.id);
2109
- invariant(match, `Could not find ${opts?.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`);
2110
- return opts?.select ? opts.select(match) : match;
2111
- }
2112
- });
2113
- return matchSelection;
2114
- }
2115
- function useRouteContext(opts) {
2116
- return useMatch({
2117
- ...opts,
2118
- select: match => opts?.select ? opts.select(match.context) : match.context
2119
- });
2120
- }
2121
- function useSearch(opts) {
2122
- return useMatch({
2123
- ...opts,
2124
- select: match => {
2125
- return opts?.select ? opts.select(match.search) : match.search;
2126
- }
2127
- });
2128
- }
2129
- function useParams(opts) {
2130
- return useRouterState({
2131
- select: state => {
2132
- const params = last(state.matches)?.params;
2133
- return opts?.select ? opts.select(params) : params;
2134
- }
2135
- });
2136
- }
2137
- function useNavigate(defaultOpts) {
2138
- const {
2139
- navigate
2140
- } = useRouter();
2141
- const match = useMatch({
2142
- strict: false
2143
- });
2144
- return React__namespace.useCallback(opts => {
2145
- return navigate({
2146
- from: opts?.to ? match.pathname : undefined,
2147
- ...defaultOpts,
2148
- ...opts
2149
- });
2150
- }, []);
2151
- }
2152
- function typedNavigate(navigate) {
2153
- return navigate;
2154
- }
2155
- function useMatchRoute() {
2156
- const {
2157
- state,
2158
- matchRoute
2159
- } = useRouter();
2160
- return React__namespace.useCallback(opts => {
2161
- const {
2162
- pending,
2163
- caseSensitive,
2164
- ...rest
2165
- } = opts;
2166
- return matchRoute(state, rest, {
2167
- pending,
2168
- caseSensitive
2169
- });
2170
- }, []);
2171
- }
2172
- function Matches() {
2173
- const {
2174
- routesById,
2175
- state
2176
- } = useRouter();
2177
-
2178
- // const matches = useRouterState({
2179
- // select: (state) => {
2180
- // return state.matches
2181
- // },
2182
- // })
2183
-
2184
2061
  const {
2185
2062
  matches
2186
2063
  } = state;
2187
- const locationKey = useRouterState({
2188
- select: d => d.resolvedLocation.state?.key
2189
- });
2064
+ const locationKey = useRouterState().location.state.key;
2190
2065
  const route = routesById[rootRouteId];
2191
2066
  const errorComponent = React__namespace.useCallback(props => {
2192
2067
  return /*#__PURE__*/React__namespace.createElement(ErrorComponent, {
@@ -2209,23 +2084,6 @@
2209
2084
  matches: matches
2210
2085
  }) : null));
2211
2086
  }
2212
- function MatchRoute(props) {
2213
- const matchRoute = useMatchRoute();
2214
- const params = matchRoute(props);
2215
- if (typeof props.children === 'function') {
2216
- return props.children(params);
2217
- }
2218
- return !!params ? props.children : null;
2219
- }
2220
- function Outlet() {
2221
- const matches = React__namespace.useContext(matchesContext).slice(1);
2222
- if (!matches[0]) {
2223
- return null;
2224
- }
2225
- return /*#__PURE__*/React__namespace.createElement(Match, {
2226
- matches: matches
2227
- });
2228
- }
2229
2087
  const defaultPending = () => null;
2230
2088
  function Match({
2231
2089
  matches
@@ -2237,13 +2095,12 @@
2237
2095
  const match = matches[0];
2238
2096
  const routeId = match?.routeId;
2239
2097
  const route = routesById[routeId];
2240
- const locationKey = useRouterState({
2241
- select: s => s.resolvedLocation.state?.key
2242
- });
2098
+ const locationKey = useRouterState().location.state?.key;
2243
2099
  const PendingComponent = route.options.pendingComponent ?? options.defaultPendingComponent ?? defaultPending;
2244
2100
  const routeErrorComponent = route.options.errorComponent ?? options.defaultErrorComponent ?? ErrorComponent;
2245
- const ResolvedSuspenseBoundary = route.options.wrapInSuspense ?? !route.isRoot ? React__namespace.Suspense : SafeFragment;
2246
- const ResolvedCatchBoundary = !!routeErrorComponent ? CatchBoundary : SafeFragment;
2101
+ const ResolvedSuspenseBoundary = route.options.wrapInSuspense ?? React__namespace.Suspense;
2102
+ // const ResolvedSuspenseBoundary = SafeFragment
2103
+
2247
2104
  const errorComponent = React__namespace.useCallback(props => {
2248
2105
  return /*#__PURE__*/React__namespace.createElement(routeErrorComponent, {
2249
2106
  ...props,
@@ -2262,7 +2119,7 @@
2262
2119
  useSearch: route.useSearch,
2263
2120
  useParams: route.useParams
2264
2121
  })
2265
- }, /*#__PURE__*/React__namespace.createElement(ResolvedCatchBoundary, {
2122
+ }, /*#__PURE__*/React__namespace.createElement(CatchBoundary, {
2266
2123
  resetKey: locationKey,
2267
2124
  errorComponent: errorComponent,
2268
2125
  onCatch: () => {
@@ -2300,169 +2157,87 @@
2300
2157
  }
2301
2158
  invariant(false, 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!');
2302
2159
  }
2303
- function SafeFragment(props) {
2304
- return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, props.children);
2305
- }
2306
-
2307
- // export function useInjectHtml() {
2308
- // const { } = useRouter()
2309
-
2310
- // return React.useCallback(
2311
- // (html: string | (() => Promise<string> | string)) => {
2312
- // router.injectHtml(html)
2313
- // },
2314
- // [],
2315
- // )
2316
- // }
2317
-
2318
- // export function useDehydrate() {
2319
- // const { } = useRouter()
2320
-
2321
- // return React.useCallback(function dehydrate<T>(
2322
- // key: any,
2323
- // data: T | (() => Promise<T> | T),
2324
- // ) {
2325
- // return router.dehydrateData(key, data)
2326
- // },
2327
- // [])
2328
- // }
2329
-
2330
- // export function useHydrate() {
2331
- // const { } = useRouter()
2332
-
2333
- // return function hydrate<T = unknown>(key: any) {
2334
- // return router.hydrateData(key) as T
2335
- // }
2336
- // }
2337
-
2338
- // This is the messiest thing ever... I'm either seriously tired (likely) or
2339
- // there has to be a better way to reset error boundaries when the
2340
- // router's location key changes.
2341
-
2342
- function CatchBoundary(props) {
2343
- const errorComponent = props.errorComponent ?? ErrorComponent;
2344
- return /*#__PURE__*/React__namespace.createElement(CatchBoundaryImpl, {
2345
- resetKey: props.resetKey,
2346
- onCatch: props.onCatch,
2347
- children: ({
2348
- error
2349
- }) => {
2350
- if (error) {
2351
- return /*#__PURE__*/React__namespace.createElement(errorComponent, {
2352
- error
2353
- });
2354
- }
2355
- return props.children;
2356
- }
2160
+ function Outlet() {
2161
+ const matches = React__namespace.useContext(matchesContext).slice(1);
2162
+ if (!matches[0]) {
2163
+ return null;
2164
+ }
2165
+ return /*#__PURE__*/React__namespace.createElement(Match, {
2166
+ matches: matches
2357
2167
  });
2358
2168
  }
2359
- class CatchBoundaryImpl extends React__namespace.Component {
2360
- state = {
2361
- error: null
2362
- };
2363
- static getDerivedStateFromError(error) {
2364
- return {
2365
- error
2366
- };
2367
- }
2368
- componentDidUpdate(prevProps, prevState) {
2369
- if (prevState.error && prevProps.resetKey !== this.props.resetKey) {
2370
- this.setState({
2371
- error: null
2372
- });
2373
- }
2374
- }
2375
- componentDidCatch(error) {
2376
- this.props.onCatch?.(error);
2377
- }
2378
- render() {
2379
- return this.props.children(this.state);
2169
+ function useMatchRoute() {
2170
+ const {
2171
+ matchRoute
2172
+ } = useRouter();
2173
+ return React__namespace.useCallback(opts => {
2174
+ const {
2175
+ pending,
2176
+ caseSensitive,
2177
+ ...rest
2178
+ } = opts;
2179
+ return matchRoute(rest, {
2180
+ pending,
2181
+ caseSensitive
2182
+ });
2183
+ }, []);
2184
+ }
2185
+ function MatchRoute(props) {
2186
+ const matchRoute = useMatchRoute();
2187
+ const params = matchRoute(props);
2188
+ if (typeof props.children === 'function') {
2189
+ return props.children(params);
2380
2190
  }
2191
+ return !!params ? props.children : null;
2381
2192
  }
2382
- function ErrorComponent({
2383
- error
2384
- }) {
2385
- const [show, setShow] = React__namespace.useState("development" !== 'production');
2386
- return /*#__PURE__*/React__namespace.createElement("div", {
2387
- style: {
2388
- padding: '.5rem',
2389
- maxWidth: '100%'
2390
- }
2391
- }, /*#__PURE__*/React__namespace.createElement("div", {
2392
- style: {
2393
- display: 'flex',
2394
- alignItems: 'center',
2395
- gap: '.5rem'
2396
- }
2397
- }, /*#__PURE__*/React__namespace.createElement("strong", {
2398
- style: {
2399
- fontSize: '1rem'
2400
- }
2401
- }, "Something went wrong!"), /*#__PURE__*/React__namespace.createElement("button", {
2402
- style: {
2403
- appearance: 'none',
2404
- fontSize: '.6em',
2405
- border: '1px solid currentColor',
2406
- padding: '.1rem .2rem',
2407
- fontWeight: 'bold',
2408
- borderRadius: '.25rem'
2409
- },
2410
- onClick: () => setShow(d => !d)
2411
- }, show ? 'Hide Error' : 'Show Error')), /*#__PURE__*/React__namespace.createElement("div", {
2412
- style: {
2413
- height: '.25rem'
2193
+ function useMatch(opts) {
2194
+ const nearestMatch = React__namespace.useContext(matchesContext)[0];
2195
+ const nearestMatchRouteId = nearestMatch?.routeId;
2196
+ const matchRouteId = useRouterState({
2197
+ select: state => {
2198
+ const match = opts?.from ? state.matches.find(d => d.routeId === opts?.from) : state.matches.find(d => d.id === nearestMatch.id);
2199
+ return match.routeId;
2414
2200
  }
2415
- }), show ? /*#__PURE__*/React__namespace.createElement("div", null, /*#__PURE__*/React__namespace.createElement("pre", {
2416
- style: {
2417
- fontSize: '.7em',
2418
- border: '1px solid red',
2419
- borderRadius: '.25rem',
2420
- padding: '.3rem',
2421
- color: 'red',
2422
- overflow: 'auto'
2201
+ });
2202
+ if (opts?.strict ?? true) {
2203
+ invariant(nearestMatchRouteId == matchRouteId, `useMatch("${matchRouteId}") is being called in a component that is meant to render the '${nearestMatchRouteId}' route. Did you mean to 'useMatch("${matchRouteId}", { strict: false })' or 'useRoute("${matchRouteId}")' instead?`);
2204
+ }
2205
+ const matchSelection = useRouterState({
2206
+ select: state => {
2207
+ const match = opts?.from ? state.matches.find(d => d.routeId === opts?.from) : state.matches.find(d => d.id === nearestMatch.id);
2208
+ invariant(match, `Could not find ${opts?.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`);
2209
+ return opts?.select ? opts.select(match) : match;
2423
2210
  }
2424
- }, error.message ? /*#__PURE__*/React__namespace.createElement("code", null, error.message) : null)) : null);
2211
+ });
2212
+ return matchSelection;
2425
2213
  }
2426
- function useBlocker(message, condition = true) {
2427
- const {
2428
- history
2429
- } = useRouter();
2430
- React__namespace.useEffect(() => {
2431
- if (!condition) return;
2432
- let unblock = history.block((retry, cancel) => {
2433
- if (window.confirm(message)) {
2434
- unblock();
2435
- retry();
2436
- }
2437
- });
2438
- return unblock;
2214
+ const matchesContext = /*#__PURE__*/React__namespace.createContext(null);
2215
+ function useMatches(opts) {
2216
+ const contextMatches = React__namespace.useContext(matchesContext);
2217
+ return useRouterState({
2218
+ select: state => {
2219
+ const matches = state.matches.slice(state.matches.findIndex(d => d.id === contextMatches[0]?.id));
2220
+ return opts?.select ? opts.select(matches) : matches;
2221
+ }
2439
2222
  });
2440
2223
  }
2441
- function Block({
2442
- message,
2443
- condition,
2444
- children
2445
- }) {
2446
- useBlocker(message, condition);
2447
- return children ?? null;
2224
+
2225
+ function useParams(opts) {
2226
+ return useRouterState({
2227
+ select: state => {
2228
+ const params = last(state.matches)?.params;
2229
+ return opts?.select ? opts.select(params) : params;
2230
+ }
2231
+ });
2448
2232
  }
2449
- function shallow(objA, objB) {
2450
- if (Object.is(objA, objB)) {
2451
- return true;
2452
- }
2453
- if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
2454
- return false;
2455
- }
2456
- const keysA = Object.keys(objA);
2457
- if (keysA.length !== Object.keys(objB).length) {
2458
- return false;
2459
- }
2460
- for (let i = 0; i < keysA.length; i++) {
2461
- if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
2462
- return false;
2233
+
2234
+ function useSearch(opts) {
2235
+ return useMatch({
2236
+ ...opts,
2237
+ select: match => {
2238
+ return opts?.select ? opts.select(match.search) : match.search;
2463
2239
  }
2464
- }
2465
- return true;
2240
+ });
2466
2241
  }
2467
2242
 
2468
2243
  const rootRouteId = '__root__';
@@ -2566,6 +2341,8 @@
2566
2341
  return opts;
2567
2342
  }
2568
2343
 
2344
+ //
2345
+
2569
2346
  class FileRoute {
2570
2347
  constructor(path) {
2571
2348
  this.path = path;
@@ -2577,12 +2354,213 @@
2577
2354
  };
2578
2355
  }
2579
2356
 
2357
+ function lazyRouteComponent(importer, exportName) {
2358
+ let loadPromise;
2359
+ const load = () => {
2360
+ if (!loadPromise) {
2361
+ loadPromise = importer();
2362
+ }
2363
+ return loadPromise;
2364
+ };
2365
+ const lazyComp = /*#__PURE__*/React__namespace.lazy(async () => {
2366
+ const moduleExports = await load();
2367
+ const comp = moduleExports[exportName ?? 'default'];
2368
+ return {
2369
+ default: comp
2370
+ };
2371
+ });
2372
+ lazyComp.preload = load;
2373
+ return lazyComp;
2374
+ }
2375
+
2376
+ function _extends() {
2377
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
2378
+ for (var i = 1; i < arguments.length; i++) {
2379
+ var source = arguments[i];
2380
+ for (var key in source) {
2381
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
2382
+ target[key] = source[key];
2383
+ }
2384
+ }
2385
+ }
2386
+ return target;
2387
+ };
2388
+ return _extends.apply(this, arguments);
2389
+ }
2390
+
2391
+ function useLinkProps(options) {
2392
+ const {
2393
+ buildLink
2394
+ } = useRouter();
2395
+ const match = useMatch({
2396
+ strict: false
2397
+ });
2398
+ const {
2399
+ // custom props
2400
+ type,
2401
+ children,
2402
+ target,
2403
+ activeProps = () => ({
2404
+ className: 'active'
2405
+ }),
2406
+ inactiveProps = () => ({}),
2407
+ activeOptions,
2408
+ disabled,
2409
+ hash,
2410
+ search,
2411
+ params,
2412
+ to,
2413
+ state,
2414
+ mask,
2415
+ preload,
2416
+ preloadDelay,
2417
+ replace,
2418
+ startTransition,
2419
+ // element props
2420
+ style,
2421
+ className,
2422
+ onClick,
2423
+ onFocus,
2424
+ onMouseEnter,
2425
+ onMouseLeave,
2426
+ onTouchStart,
2427
+ ...rest
2428
+ } = options;
2429
+ const linkInfo = buildLink({
2430
+ from: options.to ? match.pathname : undefined,
2431
+ ...options
2432
+ });
2433
+ if (linkInfo.type === 'external') {
2434
+ const {
2435
+ href
2436
+ } = linkInfo;
2437
+ return {
2438
+ href
2439
+ };
2440
+ }
2441
+ const {
2442
+ handleClick,
2443
+ handleFocus,
2444
+ handleEnter,
2445
+ handleLeave,
2446
+ handleTouchStart,
2447
+ isActive,
2448
+ next
2449
+ } = linkInfo;
2450
+ const composeHandlers = handlers => e => {
2451
+ if (e.persist) e.persist();
2452
+ handlers.filter(Boolean).forEach(handler => {
2453
+ if (e.defaultPrevented) return;
2454
+ handler(e);
2455
+ });
2456
+ };
2457
+
2458
+ // Get the active props
2459
+ const resolvedActiveProps = isActive ? functionalUpdate(activeProps, {}) ?? {} : {};
2460
+
2461
+ // Get the inactive props
2462
+ const resolvedInactiveProps = isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {};
2463
+ return {
2464
+ ...resolvedActiveProps,
2465
+ ...resolvedInactiveProps,
2466
+ ...rest,
2467
+ href: disabled ? undefined : next.maskedLocation ? next.maskedLocation.href : next.href,
2468
+ onClick: composeHandlers([onClick, handleClick]),
2469
+ onFocus: composeHandlers([onFocus, handleFocus]),
2470
+ onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),
2471
+ onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),
2472
+ onTouchStart: composeHandlers([onTouchStart, handleTouchStart]),
2473
+ target,
2474
+ style: {
2475
+ ...style,
2476
+ ...resolvedActiveProps.style,
2477
+ ...resolvedInactiveProps.style
2478
+ },
2479
+ className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined,
2480
+ ...(disabled ? {
2481
+ role: 'link',
2482
+ 'aria-disabled': true
2483
+ } : undefined),
2484
+ ['data-status']: isActive ? 'active' : undefined
2485
+ };
2486
+ }
2487
+ const Link = /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
2488
+ const linkProps = useLinkProps(props);
2489
+ return /*#__PURE__*/React__namespace.createElement("a", _extends({
2490
+ ref: ref
2491
+ }, linkProps, {
2492
+ children: typeof props.children === 'function' ? props.children({
2493
+ isActive: linkProps['data-status'] === 'active'
2494
+ }) : props.children
2495
+ }));
2496
+ });
2497
+
2498
+ function useBlocker(message, condition = true) {
2499
+ const {
2500
+ history
2501
+ } = useRouter();
2502
+ React__namespace.useEffect(() => {
2503
+ if (!condition) return;
2504
+ let unblock = history.block((retry, cancel) => {
2505
+ if (window.confirm(message)) {
2506
+ unblock();
2507
+ retry();
2508
+ }
2509
+ });
2510
+ return unblock;
2511
+ });
2512
+ }
2513
+ function Block({
2514
+ message,
2515
+ condition,
2516
+ children
2517
+ }) {
2518
+ useBlocker(message, condition);
2519
+ return children ?? null;
2520
+ }
2521
+
2522
+ function useNavigate(defaultOpts) {
2523
+ const {
2524
+ navigate
2525
+ } = useRouter();
2526
+ const match = useMatch({
2527
+ strict: false
2528
+ });
2529
+ return React__namespace.useCallback(opts => {
2530
+ return navigate({
2531
+ from: opts?.to ? match.pathname : undefined,
2532
+ ...defaultOpts,
2533
+ ...opts
2534
+ });
2535
+ }, []);
2536
+ }
2537
+ function typedNavigate(navigate) {
2538
+ return navigate;
2539
+ } //
2540
+
2541
+ function Navigate(props) {
2542
+ const {
2543
+ navigate
2544
+ } = useRouter();
2545
+ const match = useMatch({
2546
+ strict: false
2547
+ });
2548
+ useLayoutEffect(() => {
2549
+ navigate({
2550
+ from: props.to ? match.pathname : undefined,
2551
+ ...props
2552
+ });
2553
+ }, []);
2554
+ return null;
2555
+ }
2556
+
2580
2557
  exports.Block = Block;
2581
2558
  exports.CatchBoundary = CatchBoundary;
2582
2559
  exports.CatchBoundaryImpl = CatchBoundaryImpl;
2583
2560
  exports.ErrorComponent = ErrorComponent;
2584
2561
  exports.FileRoute = FileRoute;
2585
2562
  exports.Link = Link;
2563
+ exports.Match = Match;
2586
2564
  exports.MatchRoute = MatchRoute;
2587
2565
  exports.Matches = Matches;
2588
2566
  exports.Navigate = Navigate;
@@ -2635,6 +2613,7 @@
2635
2613
  exports.trimPathRight = trimPathRight;
2636
2614
  exports.typedNavigate = typedNavigate;
2637
2615
  exports.useBlocker = useBlocker;
2616
+ exports.useLayoutEffect = useLayoutEffect;
2638
2617
  exports.useLinkProps = useLinkProps;
2639
2618
  exports.useMatch = useMatch;
2640
2619
  exports.useMatchRoute = useMatchRoute;