@tanstack/react-router 0.0.1-beta.221 → 0.0.1-beta.223
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/Matches.js.map +1 -1
- package/build/cjs/RouterProvider.js +12 -7
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/useSearch.js.map +1 -1
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +12 -7
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +279 -279
- package/build/types/Matches.d.ts +25 -2
- package/build/types/RouterProvider.d.ts +2 -24
- package/build/types/fileRoute.d.ts +3 -3
- package/build/types/route.d.ts +2 -1
- package/build/types/router.d.ts +1 -1
- package/build/umd/index.development.js +12 -7
- 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/Matches.tsx +38 -2
- package/src/RouterProvider.tsx +16 -41
- package/src/route.ts +2 -1
- package/src/router.ts +1 -1
- package/src/useSearch.tsx +1 -1
- package/src/utils.ts +1 -1
package/build/types/Matches.d.ts
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { RouteMatch } from './RouterProvider';
|
|
3
2
|
import { ResolveRelativePath, ToOptions } from './link';
|
|
4
3
|
import { AnyRoute, ReactNode } from './route';
|
|
5
|
-
import { RouteById, RouteByPath, RouteIds, RoutePaths } from './routeInfo';
|
|
4
|
+
import { FullSearchSchema, ParseRoute, RouteById, RouteByPath, RouteIds, RoutePaths } from './routeInfo';
|
|
6
5
|
import { RegisteredRouter } from './router';
|
|
7
6
|
import { NoInfer, StrictOrFrom } from './utils';
|
|
7
|
+
export interface RouteMatch<TRouteTree extends AnyRoute = AnyRoute, TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id']> {
|
|
8
|
+
id: string;
|
|
9
|
+
routeId: TRouteId;
|
|
10
|
+
pathname: string;
|
|
11
|
+
params: RouteById<TRouteTree, TRouteId>['types']['allParams'];
|
|
12
|
+
status: 'pending' | 'success' | 'error';
|
|
13
|
+
isFetching: boolean;
|
|
14
|
+
invalid: boolean;
|
|
15
|
+
error: unknown;
|
|
16
|
+
paramsError: unknown;
|
|
17
|
+
searchError: unknown;
|
|
18
|
+
updatedAt: number;
|
|
19
|
+
loadPromise?: Promise<void>;
|
|
20
|
+
loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData'];
|
|
21
|
+
__resolveLoadPromise?: () => void;
|
|
22
|
+
context: RouteById<TRouteTree, TRouteId>['types']['allContext'];
|
|
23
|
+
routeSearch: RouteById<TRouteTree, TRouteId>['types']['searchSchema'];
|
|
24
|
+
search: FullSearchSchema<TRouteTree> & RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'];
|
|
25
|
+
fetchedAt: number;
|
|
26
|
+
shouldReloadDeps: any;
|
|
27
|
+
abortController: AbortController;
|
|
28
|
+
cause: 'enter' | 'stay';
|
|
29
|
+
}
|
|
30
|
+
export type AnyRouteMatch = RouteMatch<any>;
|
|
8
31
|
export declare function Matches(): JSX.Element;
|
|
9
32
|
export declare function Match({ matches }: {
|
|
10
33
|
matches: RouteMatch[];
|
|
@@ -3,10 +3,11 @@ import * as React from 'react';
|
|
|
3
3
|
import { LinkInfo, LinkOptions, NavigateOptions, ResolveRelativePath, ToOptions } from './link';
|
|
4
4
|
import { ParsedLocation } from './location';
|
|
5
5
|
import { AnyRoute } from './route';
|
|
6
|
-
import {
|
|
6
|
+
import { RouteById, RoutePaths, RoutesById } from './routeInfo';
|
|
7
7
|
import { BuildNextOptions, DehydratedRouteMatch, RegisteredRouter, Router, RouterOptions, RouterState } from './router';
|
|
8
8
|
import { NoInfer } from './utils';
|
|
9
9
|
import { MatchRouteOptions } from './Matches';
|
|
10
|
+
import { RouteMatch } from './Matches';
|
|
10
11
|
export interface CommitLocationOptions {
|
|
11
12
|
replace?: boolean;
|
|
12
13
|
resetScroll?: boolean;
|
|
@@ -62,26 +63,3 @@ export type RouterProps<TRouteTree extends AnyRoute = RegisteredRouter['routeTre
|
|
|
62
63
|
context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>;
|
|
63
64
|
};
|
|
64
65
|
export declare function useRouter<TRouteTree extends AnyRoute = RegisteredRouter['routeTree']>(): RouterContext<TRouteTree>;
|
|
65
|
-
export interface RouteMatch<TRouteTree extends AnyRoute = AnyRoute, TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id']> {
|
|
66
|
-
id: string;
|
|
67
|
-
routeId: TRouteId;
|
|
68
|
-
pathname: string;
|
|
69
|
-
params: RouteById<TRouteTree, TRouteId>['types']['allParams'];
|
|
70
|
-
status: 'pending' | 'success' | 'error';
|
|
71
|
-
isFetching: boolean;
|
|
72
|
-
invalid: boolean;
|
|
73
|
-
error: unknown;
|
|
74
|
-
paramsError: unknown;
|
|
75
|
-
searchError: unknown;
|
|
76
|
-
updatedAt: number;
|
|
77
|
-
loadPromise?: Promise<void>;
|
|
78
|
-
loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData'];
|
|
79
|
-
__resolveLoadPromise?: () => void;
|
|
80
|
-
context: RouteById<TRouteTree, TRouteId>['types']['allContext'];
|
|
81
|
-
routeSearch: RouteById<TRouteTree, TRouteId>['types']['searchSchema'];
|
|
82
|
-
search: FullSearchSchema<TRouteTree> & RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'];
|
|
83
|
-
fetchedAt: number;
|
|
84
|
-
shouldReloadDeps: any;
|
|
85
|
-
abortController: AbortController;
|
|
86
|
-
}
|
|
87
|
-
export type AnyRouteMatch = RouteMatch<any>;
|
|
@@ -23,9 +23,9 @@ export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParent
|
|
|
23
23
|
preSearchFilters?: import("./route").SearchFilter<TFullSearchSchema, TFullSearchSchema>[] | undefined;
|
|
24
24
|
postSearchFilters?: import("./route").SearchFilter<TFullSearchSchema, TFullSearchSchema>[] | undefined;
|
|
25
25
|
onError?: ((err: any) => void) | undefined;
|
|
26
|
-
onEnter?: ((match: import("./
|
|
27
|
-
onTransition?: ((match: import("./
|
|
28
|
-
onLeave?: ((match: import("./
|
|
26
|
+
onEnter?: ((match: import("./Matches").AnyRouteMatch) => void) | undefined;
|
|
27
|
+
onTransition?: ((match: import("./Matches").AnyRouteMatch) => void) | undefined;
|
|
28
|
+
onLeave?: ((match: import("./Matches").AnyRouteMatch) => void) | undefined;
|
|
29
29
|
reloadOnWindowFocus?: boolean | undefined;
|
|
30
30
|
}) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TContext, TRouterContext, TLoaderData, TChildren, TRouteTree>;
|
|
31
31
|
}
|
package/build/types/route.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { AnyRouteMatch } from './
|
|
2
|
+
import { AnyRouteMatch } from './Matches';
|
|
3
3
|
import { NavigateOptions, ParsePathParams, ToSubOptions } from './link';
|
|
4
4
|
import { ParsedLocation } from './location';
|
|
5
5
|
import { RoutePaths } from './routeInfo';
|
|
@@ -57,6 +57,7 @@ type BeforeLoadFn<TFullSearchSchema extends Record<string, any>, TParentRoute ex
|
|
|
57
57
|
location: ParsedLocation;
|
|
58
58
|
navigate: NavigateFn<AnyRoute>;
|
|
59
59
|
buildLocation: BuildLocationFn<AnyRoute>;
|
|
60
|
+
cause: 'enter' | 'stay';
|
|
60
61
|
}) => Promise<TRouteContext> | TRouteContext | void;
|
|
61
62
|
export type UpdatableRouteOptions<TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TAllContext extends AnyContext, TLoaderData extends any = unknown> = MetaOptions & {
|
|
62
63
|
caseSensitive?: boolean;
|
package/build/types/router.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { AnySearchSchema, AnyRoute, AnyContext, AnyPathParams, RouteMask } from
|
|
|
4
4
|
import { FullSearchSchema } from './routeInfo';
|
|
5
5
|
import { PickAsRequired, Updater, NonNullableUpdater } from './utils';
|
|
6
6
|
import { ErrorRouteComponent, PendingRouteComponent, RouteComponent } from './route';
|
|
7
|
-
import { RouteMatch } from './
|
|
7
|
+
import { RouteMatch } from './Matches';
|
|
8
8
|
import { ParsedLocation } from './location';
|
|
9
9
|
import { LocationState } from './location';
|
|
10
10
|
import { SearchSerializer, SearchParser } from './searchParams';
|
|
@@ -1605,9 +1605,11 @@
|
|
|
1605
1605
|
// reuse it. This is important for layout routes, which might stick
|
|
1606
1606
|
// around between navigation actions that only change leaf routes.
|
|
1607
1607
|
const existingMatch = getRouteMatch(state, matchId);
|
|
1608
|
+
const cause = state.matches.find(d => d.id === matchId) ? 'stay' : 'enter';
|
|
1608
1609
|
if (existingMatch) {
|
|
1609
1610
|
return {
|
|
1610
|
-
...existingMatch
|
|
1611
|
+
...existingMatch,
|
|
1612
|
+
cause
|
|
1611
1613
|
};
|
|
1612
1614
|
}
|
|
1613
1615
|
|
|
@@ -1631,7 +1633,8 @@
|
|
|
1631
1633
|
context: undefined,
|
|
1632
1634
|
abortController: new AbortController(),
|
|
1633
1635
|
shouldReloadDeps: undefined,
|
|
1634
|
-
fetchedAt: 0
|
|
1636
|
+
fetchedAt: 0,
|
|
1637
|
+
cause
|
|
1635
1638
|
};
|
|
1636
1639
|
return routeMatch;
|
|
1637
1640
|
});
|
|
@@ -1916,7 +1919,8 @@
|
|
|
1916
1919
|
...opts,
|
|
1917
1920
|
from: match.pathname
|
|
1918
1921
|
}),
|
|
1919
|
-
buildLocation
|
|
1922
|
+
buildLocation,
|
|
1923
|
+
cause: match.cause
|
|
1920
1924
|
})) ?? {};
|
|
1921
1925
|
const context = {
|
|
1922
1926
|
...parentContext,
|
|
@@ -1962,7 +1966,6 @@
|
|
|
1962
1966
|
if (match.isFetching) {
|
|
1963
1967
|
loadPromise = getRouteMatch(state, match.id)?.loadPromise;
|
|
1964
1968
|
} else {
|
|
1965
|
-
const cause = state.matches.find(d => d.id === match.id) ? 'stay' : 'enter';
|
|
1966
1969
|
const loaderContext = {
|
|
1967
1970
|
params: match.params,
|
|
1968
1971
|
search: match.search,
|
|
@@ -1975,13 +1978,15 @@
|
|
|
1975
1978
|
...opts,
|
|
1976
1979
|
from: match.pathname
|
|
1977
1980
|
}),
|
|
1978
|
-
cause
|
|
1981
|
+
cause: match.cause
|
|
1979
1982
|
};
|
|
1980
1983
|
|
|
1981
1984
|
// Default to reloading the route all the time
|
|
1982
1985
|
let shouldReload = true;
|
|
1983
|
-
|
|
1984
|
-
|
|
1986
|
+
let shouldReloadDeps = typeof route.options.shouldReload === 'function' ? route.options.shouldReload?.(loaderContext) : !!(route.options.shouldReload ?? true);
|
|
1987
|
+
if (match.cause === 'enter') {
|
|
1988
|
+
match.shouldReloadDeps = shouldReloadDeps;
|
|
1989
|
+
} else if (match.cause === 'stay') {
|
|
1985
1990
|
if (typeof shouldReloadDeps === 'object') {
|
|
1986
1991
|
// compare the deps to see if they've changed
|
|
1987
1992
|
shouldReload = !deepEqual(shouldReloadDeps, match.shouldReloadDeps);
|