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

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.
@@ -488,7 +488,7 @@ class Router {
488
488
  constructor(options) {
489
489
  this.options = {
490
490
  defaultPreloadDelay: 50,
491
- meta: undefined,
491
+ context: undefined,
492
492
  ...options,
493
493
  stringifySearch: options?.stringifySearch ?? defaultStringifySearch,
494
494
  parseSearch: options?.parseSearch ?? defaultParseSearch
@@ -692,9 +692,9 @@ function RouterProvider({
692
692
  const options = {
693
693
  ...router.options,
694
694
  ...rest,
695
- meta: {
696
- ...router.options.meta,
697
- ...rest?.meta
695
+ context: {
696
+ ...router.options.context,
697
+ ...rest?.context
698
698
  }
699
699
  };
700
700
  const history = React.useState(() => options.history ?? createBrowserHistory())[0];
@@ -903,16 +903,16 @@ function RouterProvider({
903
903
  paramsError: parseErrors[index],
904
904
  searchError: undefined,
905
905
  loadPromise: Promise.resolve(),
906
- meta: undefined,
906
+ context: undefined,
907
907
  abortController: new AbortController(),
908
908
  fetchedAt: 0
909
909
  };
910
910
  return routeMatch;
911
911
  });
912
912
 
913
- // Take each match and resolve its search params and meta
913
+ // Take each match and resolve its search params and context
914
914
  // This has to happen after the matches are created or found
915
- // so that we can use the parent match's search params and meta
915
+ // so that we can use the parent match's search params and context
916
916
  matches.forEach((match, i) => {
917
917
  const parentMatch = matches[i - 1];
918
918
  const route = looseRoutesById[match.routeId];
@@ -1166,22 +1166,27 @@ function RouterProvider({
1166
1166
  if (match.searchError) {
1167
1167
  handleError(match.searchError, 'VALIDATE_SEARCH');
1168
1168
  }
1169
- const parentMeta = parentMatch?.meta ?? options.meta ?? {};
1170
- const beforeLoadMeta = (await route.options.beforeLoad?.({
1169
+ const parentContext = parentMatch?.context ?? options.context ?? {};
1170
+ const beforeLoadContext = (await route.options.beforeLoad?.({
1171
1171
  search: match.search,
1172
1172
  abortController: match.abortController,
1173
1173
  params: match.params,
1174
1174
  preload: !!preload,
1175
- meta: parentMeta,
1176
- location: state.location // TODO: This might need to be latestLocationRef.current...?
1175
+ context: parentContext,
1176
+ location: state.location,
1177
+ // TODO: This might need to be latestLocationRef.current...?
1178
+ navigate: opts => navigate({
1179
+ ...opts,
1180
+ from: match.pathname
1181
+ })
1177
1182
  })) ?? {};
1178
- const meta = {
1179
- ...parentMeta,
1180
- ...beforeLoadMeta
1183
+ const context = {
1184
+ ...parentContext,
1185
+ ...beforeLoadContext
1181
1186
  };
1182
1187
  matches[index] = match = {
1183
1188
  ...match,
1184
- meta: replaceEqualDeep(match.meta, meta)
1189
+ context: replaceEqualDeep(match.context, context)
1185
1190
  };
1186
1191
  } catch (err) {
1187
1192
  handleError(err, 'BEFORE_LOAD');
@@ -1227,7 +1232,12 @@ function RouterProvider({
1227
1232
  preload: !!preload,
1228
1233
  parentMatchPromise,
1229
1234
  abortController: match.abortController,
1230
- meta: match.meta
1235
+ context: match.context,
1236
+ location: state.location,
1237
+ navigate: opts => navigate({
1238
+ ...opts,
1239
+ from: match.pathname
1240
+ })
1231
1241
  });
1232
1242
  await Promise.all([componentsPromise, loaderPromise]);
1233
1243
  if (latestPromise = checkLatest()) return await latestPromise;
@@ -1777,10 +1787,10 @@ function useMatch(opts) {
1777
1787
  });
1778
1788
  return matchSelection;
1779
1789
  }
1780
- function useRouteMeta(opts) {
1790
+ function useRouteContext(opts) {
1781
1791
  return useMatch({
1782
1792
  ...opts,
1783
- select: match => opts?.select ? opts.select(match.meta) : match.meta
1793
+ select: match => opts?.select ? opts.select(match.context) : match.context
1784
1794
  });
1785
1795
  }
1786
1796
  function useSearch(opts) {
@@ -1814,6 +1824,9 @@ function useNavigate(defaultOpts) {
1814
1824
  });
1815
1825
  }, []);
1816
1826
  }
1827
+ function typedNavigate(navigate) {
1828
+ return navigate;
1829
+ }
1817
1830
  function useMatchRoute() {
1818
1831
  const {
1819
1832
  state,
@@ -1854,7 +1867,7 @@ function Matches() {
1854
1867
  return /*#__PURE__*/React.createElement(ErrorComponent, {
1855
1868
  ...props,
1856
1869
  useMatch: route.useMatch,
1857
- useRouteMeta: route.useRouteMeta,
1870
+ useRouteContext: route.useRouteContext,
1858
1871
  useSearch: route.useSearch,
1859
1872
  useParams: route.useParams
1860
1873
  });
@@ -1910,7 +1923,7 @@ function Match({
1910
1923
  return /*#__PURE__*/React.createElement(routeErrorComponent, {
1911
1924
  ...props,
1912
1925
  useMatch: route.useMatch,
1913
- useRouteMeta: route.useRouteMeta,
1926
+ useRouteContext: route.useRouteContext,
1914
1927
  useSearch: route.useSearch,
1915
1928
  useParams: route.useParams
1916
1929
  });
@@ -1920,7 +1933,7 @@ function Match({
1920
1933
  }, /*#__PURE__*/React.createElement(ResolvedSuspenseBoundary, {
1921
1934
  fallback: /*#__PURE__*/React.createElement(PendingComponent, {
1922
1935
  useMatch: route.useMatch,
1923
- useRouteMeta: route.useRouteMeta,
1936
+ useRouteContext: route.useRouteContext,
1924
1937
  useSearch: route.useSearch,
1925
1938
  useParams: route.useParams
1926
1939
  })
@@ -1953,7 +1966,7 @@ function MatchInner({
1953
1966
  if (comp) {
1954
1967
  return /*#__PURE__*/React.createElement(comp, {
1955
1968
  useMatch: route.useMatch,
1956
- useRouteMeta: route.useRouteMeta,
1969
+ useRouteContext: route.useRouteContext,
1957
1970
  useSearch: route.useSearch,
1958
1971
  useParams: route.useParams
1959
1972
  });
@@ -2129,14 +2142,8 @@ function shallow(objA, objB) {
2129
2142
 
2130
2143
  const rootRouteId = '__root__';
2131
2144
 
2132
- // export type MetaOptions = keyof PickRequired<RouteMeta> extends never
2133
- // ? {
2134
- // meta?: RouteMeta
2135
- // }
2136
- // : {
2137
- // meta: RouteMeta
2138
- // }
2139
2145
  // The parse type here allows a zod schema to be passed directly to the validator
2146
+
2140
2147
  class Route {
2141
2148
  // Set up in this.init()
2142
2149
 
@@ -2200,11 +2207,11 @@ class Route {
2200
2207
  from: this.id
2201
2208
  });
2202
2209
  };
2203
- useRouteMeta = opts => {
2210
+ useRouteContext = opts => {
2204
2211
  return useMatch({
2205
2212
  ...opts,
2206
2213
  from: this.id,
2207
- select: d => opts?.select ? opts.select(d.meta) : d.meta
2214
+ select: d => opts?.select ? opts.select(d.context) : d.context
2208
2215
  });
2209
2216
  };
2210
2217
  useSearch = opts => {
@@ -2220,9 +2227,8 @@ class Route {
2220
2227
  });
2221
2228
  };
2222
2229
  }
2223
- class RouterMeta {
2224
- constructor() {}
2225
- createRootRoute = options => {
2230
+ function rootRouteWithContext() {
2231
+ return options => {
2226
2232
  return new RootRoute(options);
2227
2233
  };
2228
2234
  }
@@ -2246,5 +2252,5 @@ class FileRoute {
2246
2252
  };
2247
2253
  }
2248
2254
 
2249
- export { Block, CatchBoundary, CatchBoundaryImpl, ErrorComponent, FileRoute, Link, MatchRoute, Matches, Navigate, Outlet, PathParamError, RootRoute, Route, Router, RouterMeta, RouterProvider, SearchParamError, cleanPath, componentTypes, createRouteMask, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, getInitialRouterState, getRouteMatch, interpolatePath, isPlainObject, isRedirect, isServer, joinPaths, last, lazyFn, lazyRouteComponent, matchByPath, matchPathname, matchesContext, parsePathname, parseSearchWith, partialDeepEqual, pick, redirect, replaceEqualDeep, resolvePath, rootRouteId, routerContext, shallow, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, useBlocker, useLinkProps, useMatch, useMatchRoute, useMatches, useNavigate, useParams, useRouteMeta, useRouter, useRouterState, useSearch, useStableCallback };
2255
+ export { Block, CatchBoundary, CatchBoundaryImpl, ErrorComponent, FileRoute, Link, MatchRoute, Matches, Navigate, Outlet, PathParamError, RootRoute, Route, Router, RouterProvider, SearchParamError, cleanPath, componentTypes, createRouteMask, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, getInitialRouterState, getRouteMatch, interpolatePath, isPlainObject, isRedirect, isServer, joinPaths, last, lazyFn, lazyRouteComponent, matchByPath, matchPathname, matchesContext, parsePathname, parseSearchWith, partialDeepEqual, pick, redirect, replaceEqualDeep, resolvePath, rootRouteId, rootRouteWithContext, routerContext, shallow, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, typedNavigate, useBlocker, useLinkProps, useMatch, useMatchRoute, useMatches, useNavigate, useParams, useRouteContext, useRouter, useRouterState, useSearch, useStableCallback };
2250
2256
  //# sourceMappingURL=index.js.map