@tanstack/react-router 0.0.1-beta.22 → 0.0.1-beta.24

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.
@@ -877,12 +877,6 @@ function invariant(condition, message) {
877
877
  throw new Error(value);
878
878
  }
879
879
 
880
- // type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
881
- // k: infer I,
882
- // ) => any
883
- // ? I
884
- // : never
885
-
886
880
  /**
887
881
  * This function returns `a` if `b` is deeply equal.
888
882
  * If not, it will replace any deeply equal children of `b` with those of `a`.
@@ -1104,10 +1098,7 @@ function matchPathname(currentPathname, matchLocation) {
1104
1098
 
1105
1099
  if (matchLocation.to && !pathParams) {
1106
1100
  return;
1107
- } // if (matchLocation.search && !searchMatched) {
1108
- // return
1109
- // }
1110
-
1101
+ }
1111
1102
 
1112
1103
  return pathParams != null ? pathParams : {};
1113
1104
  }
@@ -1344,6 +1335,7 @@ function createRoute(routeConfig, options, parent, router) {
1344
1335
  })();
1345
1336
 
1346
1337
  let route = {
1338
+ routeInfo: undefined,
1347
1339
  routeId: id,
1348
1340
  routeRouteId: routeId,
1349
1341
  routePath,
@@ -1717,6 +1709,7 @@ function createRouter(userOptions) {
1717
1709
  options: originalOptions,
1718
1710
  listeners: [],
1719
1711
  // Resolved after construction
1712
+ context: {},
1720
1713
  basepath: '',
1721
1714
  routeTree: undefined,
1722
1715
  routesById: {},
@@ -1861,7 +1854,19 @@ function createRouter(userOptions) {
1861
1854
 
1862
1855
  const matches = router.matchRoutes(router.location.pathname, {
1863
1856
  strictParseParams: true
1864
- });
1857
+ }); // Check if each match middleware to see if the route can be accessed
1858
+
1859
+ try {
1860
+ await Promise.all(matches.map(match => match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
1861
+ context: router.context
1862
+ })));
1863
+ } catch (err) {
1864
+ if (err != null && err.then) {
1865
+ await new Promise(() => {});
1866
+ }
1867
+
1868
+ throw err;
1869
+ }
1865
1870
 
1866
1871
  if (typeof document !== 'undefined') {
1867
1872
  router.state = _extends({}, router.state, {
@@ -1931,7 +1936,7 @@ function createRouter(userOptions) {
1931
1936
  });
1932
1937
  });
1933
1938
  entering.forEach(d => {
1934
- d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
1939
+ d.__.onExit = d.options.onLoaded == null ? void 0 : d.options.onLoaded({
1935
1940
  params: d.params,
1936
1941
  search: d.search
1937
1942
  });
@@ -2729,6 +2734,8 @@ function createReactRouter(opts) {
2729
2734
  return coreRouter;
2730
2735
  }
2731
2736
  function RouterProvider(_ref2) {
2737
+ var _router$options$useCo;
2738
+
2732
2739
  let {
2733
2740
  children,
2734
2741
  router
@@ -2736,9 +2743,11 @@ function RouterProvider(_ref2) {
2736
2743
  rest = _objectWithoutPropertiesLoose(_ref2, _excluded3);
2737
2744
 
2738
2745
  router.update(rest);
2746
+ const defaultRouterContext = React.useRef({});
2747
+ const userContext = (_router$options$useCo = router.options.useContext == null ? void 0 : router.options.useContext()) != null ? _router$options$useCo : defaultRouterContext.current;
2748
+ router.context = userContext;
2739
2749
  useRouterSubscription(router);
2740
2750
  React.useEffect(() => {
2741
- console.log('hello');
2742
2751
  return router.mount();
2743
2752
  }, [router]);
2744
2753
  return /*#__PURE__*/React.createElement(routerContext.Provider, {
@@ -2773,6 +2782,9 @@ function useRoute(routeId) {
2773
2782
  const router = useRouter();
2774
2783
  return router.useRoute(routeId);
2775
2784
  }
2785
+ function useSearch(_routeId) {
2786
+ return useRouter().state.location.search;
2787
+ }
2776
2788
  function linkProps(props) {
2777
2789
  const router = useRouter();
2778
2790
  return router.linkProps(props);
@@ -2812,7 +2824,6 @@ function Outlet() {
2812
2824
  return /*#__PURE__*/React.createElement((_ref4 = (_ref5 = match.__.component) != null ? _ref5 : router.options.defaultComponent) != null ? _ref4 : Outlet);
2813
2825
  }
2814
2826
 
2815
- console.log(match.matchId, 'suspend');
2816
2827
  throw match.__.loadPromise;
2817
2828
  })())));
2818
2829
  }
@@ -2899,5 +2910,5 @@ function Prompt(_ref7) {
2899
2910
  return children != null ? children : null;
2900
2911
  }
2901
2912
 
2902
- export { DefaultErrorBoundary, Link, MatchRoute, MatchesProvider, Outlet, Prompt, RouterProvider, cleanPath, createBrowserHistory, createHashHistory, createMemoryHistory, createReactRouter, createRoute, createRouteConfig, createRouteMatch, createRouter, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, invariant, joinPaths, last, lazy, linkProps, matchByPath, matchPathname, matchesContext, parsePathname, parseSearchWith, pick, replaceEqualDeep, resolvePath, rootRouteId, routerContext, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, useMatch, useMatches, useNearestMatch, usePrompt, useRoute, useRouter, warning };
2913
+ export { DefaultErrorBoundary, Link, MatchRoute, MatchesProvider, Outlet, Prompt, RouterProvider, cleanPath, createBrowserHistory, createHashHistory, createMemoryHistory, createReactRouter, createRoute, createRouteConfig, createRouteMatch, createRouter, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, invariant, joinPaths, last, lazy, linkProps, matchByPath, matchPathname, matchesContext, parsePathname, parseSearchWith, pick, replaceEqualDeep, resolvePath, rootRouteId, routerContext, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, useMatch, useMatches, useNearestMatch, usePrompt, useRoute, useRouter, useSearch, warning };
2903
2914
  //# sourceMappingURL=index.js.map