@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.
@@ -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":"4053-59","name":"\u0000rollupPluginBabelHelpers.js"},{"name":"packages","children":[{"name":"router-core/build/esm/index.js","uid":"4053-61"},{"name":"react-router/src/index.tsx","uid":"4053-63"}]}]}],"isRoot":true},"nodeParts":{"4053-59":{"renderedLength":798,"gzipLength":366,"brotliLength":0,"mainUid":"4053-58"},"4053-61":{"renderedLength":75162,"gzipLength":15777,"brotliLength":0,"mainUid":"4053-60"},"4053-63":{"renderedLength":12803,"gzipLength":3212,"brotliLength":0,"mainUid":"4053-62"}},"nodeMetas":{"4053-58":{"id":"\u0000rollupPluginBabelHelpers.js","moduleParts":{"index.production.js":"4053-59"},"imported":[],"importedBy":[{"uid":"4053-62"}]},"4053-60":{"id":"/packages/router-core/build/esm/index.js","moduleParts":{"index.production.js":"4053-61"},"imported":[],"importedBy":[{"uid":"4053-62"}]},"4053-62":{"id":"/packages/react-router/src/index.tsx","moduleParts":{"index.production.js":"4053-63"},"imported":[{"uid":"4053-58"},{"uid":"4053-64"},{"uid":"4053-65"},{"uid":"4053-60"}],"importedBy":[],"isEntry":true},"4053-64":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"4053-62"}],"isExternal":true},"4053-65":{"id":"use-sync-external-store/shim","moduleParts":{},"imported":[],"importedBy":[{"uid":"4053-62"}],"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":"64ae-59","name":"\u0000rollupPluginBabelHelpers.js"},{"name":"packages","children":[{"name":"router-core/build/esm/index.js","uid":"64ae-61"},{"name":"react-router/src/index.tsx","uid":"64ae-63"}]}]}],"isRoot":true},"nodeParts":{"64ae-59":{"renderedLength":798,"gzipLength":366,"brotliLength":0,"mainUid":"64ae-58"},"64ae-61":{"renderedLength":75397,"gzipLength":15789,"brotliLength":0,"mainUid":"64ae-60"},"64ae-63":{"renderedLength":13128,"gzipLength":3268,"brotliLength":0,"mainUid":"64ae-62"}},"nodeMetas":{"64ae-58":{"id":"\u0000rollupPluginBabelHelpers.js","moduleParts":{"index.production.js":"64ae-59"},"imported":[],"importedBy":[{"uid":"64ae-62"}]},"64ae-60":{"id":"/packages/router-core/build/esm/index.js","moduleParts":{"index.production.js":"64ae-61"},"imported":[],"importedBy":[{"uid":"64ae-62"}]},"64ae-62":{"id":"/packages/react-router/src/index.tsx","moduleParts":{"index.production.js":"64ae-63"},"imported":[{"uid":"64ae-58"},{"uid":"64ae-64"},{"uid":"64ae-65"},{"uid":"64ae-60"}],"importedBy":[],"isEntry":true},"64ae-64":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"64ae-62"}],"isExternal":true},"64ae-65":{"id":"use-sync-external-store/shim","moduleParts":{},"imported":[],"importedBy":[{"uid":"64ae-62"}],"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": "4053-67",
10
+ "uid": "64ae-67",
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": "4053-69"
18
+ "uid": "64ae-69"
19
19
  },
20
20
  {
21
21
  "name": "react-router/src/index.tsx",
22
- "uid": "4053-71"
22
+ "uid": "64ae-71"
23
23
  }
24
24
  ]
25
25
  }
@@ -29,90 +29,90 @@
29
29
  "isRoot": true
30
30
  },
31
31
  "nodeParts": {
32
- "4053-67": {
32
+ "64ae-67": {
33
33
  "renderedLength": 798,
34
34
  "gzipLength": 366,
35
35
  "brotliLength": 0,
36
- "mainUid": "4053-66"
36
+ "mainUid": "64ae-66"
37
37
  },
38
- "4053-69": {
39
- "renderedLength": 75162,
40
- "gzipLength": 15777,
38
+ "64ae-69": {
39
+ "renderedLength": 75397,
40
+ "gzipLength": 15789,
41
41
  "brotliLength": 0,
42
- "mainUid": "4053-68"
42
+ "mainUid": "64ae-68"
43
43
  },
44
- "4053-71": {
45
- "renderedLength": 12803,
46
- "gzipLength": 3212,
44
+ "64ae-71": {
45
+ "renderedLength": 13128,
46
+ "gzipLength": 3268,
47
47
  "brotliLength": 0,
48
- "mainUid": "4053-70"
48
+ "mainUid": "64ae-70"
49
49
  }
50
50
  },
51
51
  "nodeMetas": {
52
- "4053-66": {
52
+ "64ae-66": {
53
53
  "id": "\u0000rollupPluginBabelHelpers.js",
54
54
  "moduleParts": {
55
- "index.production.js": "4053-67"
55
+ "index.production.js": "64ae-67"
56
56
  },
57
57
  "imported": [],
58
58
  "importedBy": [
59
59
  {
60
- "uid": "4053-70"
60
+ "uid": "64ae-70"
61
61
  }
62
62
  ]
63
63
  },
64
- "4053-68": {
64
+ "64ae-68": {
65
65
  "id": "/packages/router-core/build/esm/index.js",
66
66
  "moduleParts": {
67
- "index.production.js": "4053-69"
67
+ "index.production.js": "64ae-69"
68
68
  },
69
69
  "imported": [],
70
70
  "importedBy": [
71
71
  {
72
- "uid": "4053-70"
72
+ "uid": "64ae-70"
73
73
  }
74
74
  ]
75
75
  },
76
- "4053-70": {
76
+ "64ae-70": {
77
77
  "id": "/packages/react-router/src/index.tsx",
78
78
  "moduleParts": {
79
- "index.production.js": "4053-71"
79
+ "index.production.js": "64ae-71"
80
80
  },
81
81
  "imported": [
82
82
  {
83
- "uid": "4053-66"
83
+ "uid": "64ae-66"
84
84
  },
85
85
  {
86
- "uid": "4053-72"
86
+ "uid": "64ae-72"
87
87
  },
88
88
  {
89
- "uid": "4053-73"
89
+ "uid": "64ae-73"
90
90
  },
91
91
  {
92
- "uid": "4053-68"
92
+ "uid": "64ae-68"
93
93
  }
94
94
  ],
95
95
  "importedBy": [],
96
96
  "isEntry": true
97
97
  },
98
- "4053-72": {
98
+ "64ae-72": {
99
99
  "id": "react",
100
100
  "moduleParts": {},
101
101
  "imported": [],
102
102
  "importedBy": [
103
103
  {
104
- "uid": "4053-70"
104
+ "uid": "64ae-70"
105
105
  }
106
106
  ],
107
107
  "isExternal": true
108
108
  },
109
- "4053-73": {
109
+ "64ae-73": {
110
110
  "id": "use-sync-external-store/shim",
111
111
  "moduleParts": {},
112
112
  "imported": [],
113
113
  "importedBy": [
114
114
  {
115
- "uid": "4053-70"
115
+ "uid": "64ae-70"
116
116
  }
117
117
  ],
118
118
  "isExternal": true
@@ -9,7 +9,7 @@
9
9
  * @license MIT
10
10
  */
11
11
  import * as React from 'react';
12
- import { AnyRouteConfig, RouteConfig, AnyAllRouteInfo, AllRouteInfo, RouterState, RouteMatch, RouteInfo, DefaultAllRouteInfo, AnyRouteInfo, ResolveRelativePath, NoInfer, CheckId, ToIdOption, Router, ValidFromPath, ToOptions, MatchRouteOptions, RouteInfoByPath, RouterOptions, Route, LinkOptions } from '@tanstack/router-core';
12
+ import { AnyRouteConfig, RouterContext, RouteConfig, AnyAllRouteInfo, AllRouteInfo, RouterState, RouteMatch, RouteInfo, DefaultAllRouteInfo, AnyRouteInfo, ResolveRelativePath, NoInfer, CheckId, ToIdOption, Router, ValidFromPath, ToOptions, MatchRouteOptions, RouteInfoByPath, RouterOptions, Route, LinkOptions } from '@tanstack/router-core';
13
13
  export * from '@tanstack/router-core';
14
14
 
15
15
  interface RegisterRouter {
@@ -44,6 +44,9 @@ declare module '@tanstack/router-core' {
44
44
  interface FrameworkGenerics {
45
45
  Component: RouteComponent;
46
46
  }
47
+ interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
48
+ useContext?: () => RouterContext;
49
+ }
47
50
  interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>> {
48
51
  useState: () => RouterState;
49
52
  useRoute: <TId extends keyof TAllRouteInfo['routeInfoById']>(routeId: TId) => Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>;
@@ -92,6 +95,7 @@ declare function useMatch<TId extends keyof RegisteredAllRouteInfo['routeInfoByI
92
95
  }): TStrict extends true ? RouteMatch<RegisteredAllRouteInfo, RegisteredAllRouteInfo['routeInfoById'][TId]> : RouteMatch<RegisteredAllRouteInfo, RegisteredAllRouteInfo['routeInfoById'][TId]> | undefined;
93
96
  declare function useNearestMatch(): RouteMatch<RegisteredAllRouteInfo, RouteInfo>;
94
97
  declare function useRoute<TId extends keyof RegisteredAllRouteInfo['routeInfoById']>(routeId: TId): Route<RegisteredAllRouteInfo, RegisteredAllRouteInfo['routeInfoById'][TId]>;
98
+ declare function useSearch<TId extends keyof RegisteredAllRouteInfo['routeInfoById'] = keyof RegisteredAllRouteInfo['routeInfoById']>(_routeId?: TId): RegisteredAllRouteInfo['fullSearchSchema'];
95
99
  declare function linkProps<TTo extends string = '.'>(props: MakeLinkPropsOptions<RegisteredAllRouteInfo, '/', TTo>): React.AnchorHTMLAttributes<HTMLAnchorElement>;
96
100
  declare function MatchRoute<TTo extends string = '.'>(props: MakeMatchRouteOptions<RegisteredAllRouteInfo, '/', TTo>): JSX.Element;
97
101
  declare function Outlet(): JSX.Element | null;
@@ -101,4 +105,4 @@ declare function DefaultErrorBoundary({ error }: {
101
105
  declare function usePrompt(message: string, when: boolean | any): void;
102
106
  declare function Prompt({ message, when, children }: PromptProps): React.ReactNode;
103
107
 
104
- export { DefaultErrorBoundary, Link, MatchRoute, MatchesProvider, MatchesProviderProps, Outlet, Prompt, PromptProps, RegisterRouter, RegisteredAllRouteInfo, RegisteredRouter, RouteComponent, RouterProps, RouterProvider, SyncRouteComponent, createReactRouter, lazy, linkProps, matchesContext, routerContext, useMatch, useMatches, useNearestMatch, usePrompt, useRoute, useRouter };
108
+ export { DefaultErrorBoundary, Link, MatchRoute, MatchesProvider, MatchesProviderProps, Outlet, Prompt, PromptProps, RegisterRouter, RegisteredAllRouteInfo, RegisteredRouter, RouteComponent, RouterProps, RouterProvider, SyncRouteComponent, createReactRouter, lazy, linkProps, matchesContext, routerContext, useMatch, useMatches, useNearestMatch, usePrompt, useRoute, useRouter, useSearch };
@@ -893,12 +893,6 @@
893
893
  throw new Error(value);
894
894
  }
895
895
 
896
- // type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
897
- // k: infer I,
898
- // ) => any
899
- // ? I
900
- // : never
901
-
902
896
  /**
903
897
  * This function returns `a` if `b` is deeply equal.
904
898
  * If not, it will replace any deeply equal children of `b` with those of `a`.
@@ -1120,10 +1114,7 @@
1120
1114
 
1121
1115
  if (matchLocation.to && !pathParams) {
1122
1116
  return;
1123
- } // if (matchLocation.search && !searchMatched) {
1124
- // return
1125
- // }
1126
-
1117
+ }
1127
1118
 
1128
1119
  return pathParams != null ? pathParams : {};
1129
1120
  }
@@ -1360,6 +1351,7 @@
1360
1351
  })();
1361
1352
 
1362
1353
  let route = {
1354
+ routeInfo: undefined,
1363
1355
  routeId: id,
1364
1356
  routeRouteId: routeId,
1365
1357
  routePath,
@@ -1733,6 +1725,7 @@
1733
1725
  options: originalOptions,
1734
1726
  listeners: [],
1735
1727
  // Resolved after construction
1728
+ context: {},
1736
1729
  basepath: '',
1737
1730
  routeTree: undefined,
1738
1731
  routesById: {},
@@ -1877,7 +1870,19 @@
1877
1870
 
1878
1871
  const matches = router.matchRoutes(router.location.pathname, {
1879
1872
  strictParseParams: true
1880
- });
1873
+ }); // Check if each match middleware to see if the route can be accessed
1874
+
1875
+ try {
1876
+ await Promise.all(matches.map(match => match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
1877
+ context: router.context
1878
+ })));
1879
+ } catch (err) {
1880
+ if (err != null && err.then) {
1881
+ await new Promise(() => {});
1882
+ }
1883
+
1884
+ throw err;
1885
+ }
1881
1886
 
1882
1887
  if (typeof document !== 'undefined') {
1883
1888
  router.state = _extends({}, router.state, {
@@ -1947,7 +1952,7 @@
1947
1952
  });
1948
1953
  });
1949
1954
  entering.forEach(d => {
1950
- d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
1955
+ d.__.onExit = d.options.onLoaded == null ? void 0 : d.options.onLoaded({
1951
1956
  params: d.params,
1952
1957
  search: d.search
1953
1958
  });
@@ -2745,6 +2750,8 @@
2745
2750
  return coreRouter;
2746
2751
  }
2747
2752
  function RouterProvider(_ref2) {
2753
+ var _router$options$useCo;
2754
+
2748
2755
  let {
2749
2756
  children,
2750
2757
  router
@@ -2752,9 +2759,11 @@
2752
2759
  rest = _objectWithoutPropertiesLoose(_ref2, _excluded3);
2753
2760
 
2754
2761
  router.update(rest);
2762
+ const defaultRouterContext = React__namespace.useRef({});
2763
+ const userContext = (_router$options$useCo = router.options.useContext == null ? void 0 : router.options.useContext()) != null ? _router$options$useCo : defaultRouterContext.current;
2764
+ router.context = userContext;
2755
2765
  useRouterSubscription(router);
2756
2766
  React__namespace.useEffect(() => {
2757
- console.log('hello');
2758
2767
  return router.mount();
2759
2768
  }, [router]);
2760
2769
  return /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
@@ -2789,6 +2798,9 @@
2789
2798
  const router = useRouter();
2790
2799
  return router.useRoute(routeId);
2791
2800
  }
2801
+ function useSearch(_routeId) {
2802
+ return useRouter().state.location.search;
2803
+ }
2792
2804
  function linkProps(props) {
2793
2805
  const router = useRouter();
2794
2806
  return router.linkProps(props);
@@ -2828,7 +2840,6 @@
2828
2840
  return /*#__PURE__*/React__namespace.createElement((_ref4 = (_ref5 = match.__.component) != null ? _ref5 : router.options.defaultComponent) != null ? _ref4 : Outlet);
2829
2841
  }
2830
2842
 
2831
- console.log(match.matchId, 'suspend');
2832
2843
  throw match.__.loadPromise;
2833
2844
  })())));
2834
2845
  }
@@ -2962,6 +2973,7 @@
2962
2973
  exports.usePrompt = usePrompt;
2963
2974
  exports.useRoute = useRoute;
2964
2975
  exports.useRouter = useRouter;
2976
+ exports.useSearch = useSearch;
2965
2977
  exports.warning = warning;
2966
2978
 
2967
2979
  Object.defineProperty(exports, '__esModule', { value: true });