@tanstack/react-router 0.0.1-beta.215 → 0.0.1-beta.216
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 +29 -14
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/route.js.map +1 -1
- package/build/esm/index.js +29 -14
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +261 -261
- package/build/types/route.d.ts +4 -3
- package/build/umd/index.development.js +29 -14
- 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/RouterProvider.tsx +46 -21
- package/src/route.ts +11 -3
package/build/types/route.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export type ParamsFallback<TPath extends string, TParams> = unknown extends TPar
|
|
|
34
34
|
export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext, TLoaderData extends any = unknown> = RoutePathOptions<TCustomId, TPath> & {
|
|
35
35
|
getParentRoute: () => TParentRoute;
|
|
36
36
|
validateSearch?: SearchSchemaValidator<TSearchSchema>;
|
|
37
|
+
shouldReload?: (match: LoaderFnContext<TAllParams, TFullSearchSchema, TAllContext, TRouteContext>) => any;
|
|
37
38
|
} & (keyof PickRequired<RouteContext> extends never ? {
|
|
38
39
|
beforeLoad?: BeforeLoadFn<TFullSearchSchema, TParentRoute, TAllParams, TRouteContext>;
|
|
39
40
|
} : {
|
|
@@ -85,9 +86,7 @@ export type DefinedPathParamWarning = 'Path params cannot be redefined by child
|
|
|
85
86
|
export type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
|
|
86
87
|
[Key in keyof TParentParams]?: DefinedPathParamWarning;
|
|
87
88
|
};
|
|
88
|
-
export type RouteLoadFn<TAllParams = {}, TFullSearchSchema extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext, TLoaderData extends any = unknown> = (match: LoaderFnContext<TAllParams, TFullSearchSchema, TAllContext, TRouteContext>
|
|
89
|
-
parentMatchPromise?: Promise<void>;
|
|
90
|
-
}) => Promise<TLoaderData> | TLoaderData;
|
|
89
|
+
export type RouteLoadFn<TAllParams = {}, TFullSearchSchema extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext, TLoaderData extends any = unknown> = (match: LoaderFnContext<TAllParams, TFullSearchSchema, TAllContext, TRouteContext>) => Promise<TLoaderData> | TLoaderData;
|
|
91
90
|
export interface LoaderFnContext<TAllParams = {}, TFullSearchSchema extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext> {
|
|
92
91
|
abortController: AbortController;
|
|
93
92
|
preload: boolean;
|
|
@@ -96,6 +95,8 @@ export interface LoaderFnContext<TAllParams = {}, TFullSearchSchema extends Reco
|
|
|
96
95
|
context: Expand<Assign<TAllContext, TRouteContext>>;
|
|
97
96
|
location: ParsedLocation<TFullSearchSchema>;
|
|
98
97
|
navigate: (opts: NavigateOptions<AnyRoute>) => Promise<void>;
|
|
98
|
+
parentMatchPromise?: Promise<void>;
|
|
99
|
+
cause: 'enter' | 'stay';
|
|
99
100
|
}
|
|
100
101
|
export type SearchFilter<T, U = T> = (prev: T) => U;
|
|
101
102
|
export type ResolveId<TParentRoute, TCustomId extends string, TPath extends string> = TParentRoute extends {
|
|
@@ -1687,17 +1687,8 @@
|
|
|
1687
1687
|
if (match.isFetching) {
|
|
1688
1688
|
loadPromise = getRouteMatch(state, match.id)?.loadPromise;
|
|
1689
1689
|
} else {
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
isFetching: true
|
|
1693
|
-
};
|
|
1694
|
-
const componentsPromise = Promise.all(componentTypes.map(async type => {
|
|
1695
|
-
const component = route.options[type];
|
|
1696
|
-
if (component?.preload) {
|
|
1697
|
-
await component.preload();
|
|
1698
|
-
}
|
|
1699
|
-
}));
|
|
1700
|
-
const loaderPromise = route.options.loader?.({
|
|
1690
|
+
const cause = state.matches.find(d => d.id === match.id) ? 'stay' : 'enter';
|
|
1691
|
+
const loaderContext = {
|
|
1701
1692
|
params: match.params,
|
|
1702
1693
|
search: match.search,
|
|
1703
1694
|
preload: !!preload,
|
|
@@ -1708,9 +1699,33 @@
|
|
|
1708
1699
|
navigate: opts => navigate({
|
|
1709
1700
|
...opts,
|
|
1710
1701
|
from: match.pathname
|
|
1711
|
-
})
|
|
1712
|
-
|
|
1713
|
-
|
|
1702
|
+
}),
|
|
1703
|
+
cause
|
|
1704
|
+
};
|
|
1705
|
+
|
|
1706
|
+
// Default to reloading the route all the time
|
|
1707
|
+
const shouldReload = route.options.shouldReload?.(loaderContext) ?? true;
|
|
1708
|
+
|
|
1709
|
+
// If the user doesn't want the route to reload, just
|
|
1710
|
+
// resolve with the existing loader data
|
|
1711
|
+
|
|
1712
|
+
if (!shouldReload) {
|
|
1713
|
+
loadPromise = Promise.resolve(match.loaderData);
|
|
1714
|
+
} else {
|
|
1715
|
+
// Otherwise, load the route
|
|
1716
|
+
matches[index] = match = {
|
|
1717
|
+
...match,
|
|
1718
|
+
isFetching: true
|
|
1719
|
+
};
|
|
1720
|
+
const componentsPromise = Promise.all(componentTypes.map(async type => {
|
|
1721
|
+
const component = route.options[type];
|
|
1722
|
+
if (component?.preload) {
|
|
1723
|
+
await component.preload();
|
|
1724
|
+
}
|
|
1725
|
+
}));
|
|
1726
|
+
const loaderPromise = route.options.loader?.(loaderContext);
|
|
1727
|
+
loadPromise = Promise.all([componentsPromise, loaderPromise]).then(d => d[1]);
|
|
1728
|
+
}
|
|
1714
1729
|
}
|
|
1715
1730
|
matches[index] = match = {
|
|
1716
1731
|
...match,
|