@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.
- package/build/cjs/RouterProvider.js +25 -15
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/fileRoute.js.map +1 -1
- package/build/cjs/index.js +3 -2
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/react.js +11 -7
- package/build/cjs/react.js.map +1 -1
- package/build/cjs/route.js +6 -13
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +1 -1
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +41 -35
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +171 -171
- package/build/types/RouteMatch.d.ts +1 -1
- package/build/types/fileRoute.d.ts +17 -2
- package/build/types/react.d.ts +5 -4
- package/build/types/route.d.ts +46 -39
- package/build/types/router.d.ts +5 -5
- package/build/umd/index.development.js +43 -36
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/RouteMatch.ts +1 -1
- package/src/RouterProvider.tsx +19 -15
- package/src/fileRoute.ts +10 -8
- package/src/react.tsx +27 -11
- package/src/route.ts +112 -106
- package/src/router.ts +6 -6
package/build/esm/index.js
CHANGED
|
@@ -488,7 +488,7 @@ class Router {
|
|
|
488
488
|
constructor(options) {
|
|
489
489
|
this.options = {
|
|
490
490
|
defaultPreloadDelay: 50,
|
|
491
|
-
|
|
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
|
-
|
|
696
|
-
...router.options.
|
|
697
|
-
...rest?.
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
1170
|
-
const
|
|
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
|
-
|
|
1176
|
-
location: state.location
|
|
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
|
|
1179
|
-
...
|
|
1180
|
-
...
|
|
1183
|
+
const context = {
|
|
1184
|
+
...parentContext,
|
|
1185
|
+
...beforeLoadContext
|
|
1181
1186
|
};
|
|
1182
1187
|
matches[index] = match = {
|
|
1183
1188
|
...match,
|
|
1184
|
-
|
|
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
|
-
|
|
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
|
|
1790
|
+
function useRouteContext(opts) {
|
|
1781
1791
|
return useMatch({
|
|
1782
1792
|
...opts,
|
|
1783
|
-
select: match => opts?.select ? opts.select(match.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2210
|
+
useRouteContext = opts => {
|
|
2204
2211
|
return useMatch({
|
|
2205
2212
|
...opts,
|
|
2206
2213
|
from: this.id,
|
|
2207
|
-
select: d => opts?.select ? opts.select(d.
|
|
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
|
-
|
|
2224
|
-
|
|
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,
|
|
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
|