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

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
  }
@@ -1717,6 +1708,7 @@ function createRouter(userOptions) {
1717
1708
  options: originalOptions,
1718
1709
  listeners: [],
1719
1710
  // Resolved after construction
1711
+ context: {},
1720
1712
  basepath: '',
1721
1713
  routeTree: undefined,
1722
1714
  routesById: {},
@@ -1861,7 +1853,19 @@ function createRouter(userOptions) {
1861
1853
 
1862
1854
  const matches = router.matchRoutes(router.location.pathname, {
1863
1855
  strictParseParams: true
1864
- });
1856
+ }); // Check if each match middleware to see if the route can be accessed
1857
+
1858
+ try {
1859
+ await Promise.all(matches.map(match => match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
1860
+ context: router.context
1861
+ })));
1862
+ } catch (err) {
1863
+ if (err != null && err.then) {
1864
+ await new Promise(() => {});
1865
+ }
1866
+
1867
+ throw err;
1868
+ }
1865
1869
 
1866
1870
  if (typeof document !== 'undefined') {
1867
1871
  router.state = _extends({}, router.state, {
@@ -1931,7 +1935,7 @@ function createRouter(userOptions) {
1931
1935
  });
1932
1936
  });
1933
1937
  entering.forEach(d => {
1934
- d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
1938
+ d.__.onExit = d.options.onLoaded == null ? void 0 : d.options.onLoaded({
1935
1939
  params: d.params,
1936
1940
  search: d.search
1937
1941
  });
@@ -2729,6 +2733,8 @@ function createReactRouter(opts) {
2729
2733
  return coreRouter;
2730
2734
  }
2731
2735
  function RouterProvider(_ref2) {
2736
+ var _router$options$useCo;
2737
+
2732
2738
  let {
2733
2739
  children,
2734
2740
  router
@@ -2736,9 +2742,11 @@ function RouterProvider(_ref2) {
2736
2742
  rest = _objectWithoutPropertiesLoose(_ref2, _excluded3);
2737
2743
 
2738
2744
  router.update(rest);
2745
+ const defaultRouterContext = React.useRef({});
2746
+ const userContext = (_router$options$useCo = router.options.useContext == null ? void 0 : router.options.useContext()) != null ? _router$options$useCo : defaultRouterContext.current;
2747
+ router.context = userContext;
2739
2748
  useRouterSubscription(router);
2740
2749
  React.useEffect(() => {
2741
- console.log('hello');
2742
2750
  return router.mount();
2743
2751
  }, [router]);
2744
2752
  return /*#__PURE__*/React.createElement(routerContext.Provider, {
@@ -2773,6 +2781,9 @@ function useRoute(routeId) {
2773
2781
  const router = useRouter();
2774
2782
  return router.useRoute(routeId);
2775
2783
  }
2784
+ function useSearch(_routeId) {
2785
+ return useRouter().state.location.search;
2786
+ }
2776
2787
  function linkProps(props) {
2777
2788
  const router = useRouter();
2778
2789
  return router.linkProps(props);
@@ -2812,7 +2823,6 @@ function Outlet() {
2812
2823
  return /*#__PURE__*/React.createElement((_ref4 = (_ref5 = match.__.component) != null ? _ref5 : router.options.defaultComponent) != null ? _ref4 : Outlet);
2813
2824
  }
2814
2825
 
2815
- console.log(match.matchId, 'suspend');
2816
2826
  throw match.__.loadPromise;
2817
2827
  })())));
2818
2828
  }
@@ -2899,5 +2909,5 @@ function Prompt(_ref7) {
2899
2909
  return children != null ? children : null;
2900
2910
  }
2901
2911
 
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 };
2912
+ 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
2913
  //# sourceMappingURL=index.js.map