@tanstack/router-core 1.160.0 → 1.161.3
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/dist/cjs/router.cjs +25 -21
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +1 -1
- package/dist/esm/router.d.ts +1 -1
- package/dist/esm/router.js +25 -21
- package/dist/esm/router.js.map +1 -1
- package/package.json +2 -2
- package/src/router.ts +37 -22
package/dist/cjs/router.d.cts
CHANGED
|
@@ -457,7 +457,7 @@ export type RouterContextOptions<TRouteTree extends AnyRoute> = AnyContext exten
|
|
|
457
457
|
context: InferRouterContext<TRouteTree>;
|
|
458
458
|
};
|
|
459
459
|
export type RouterConstructorOptions<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory, TDehydrated extends Record<string, any>> = Omit<RouterOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>, 'context' | 'serializationAdapters' | 'defaultSsr'> & RouterContextOptions<TRouteTree>;
|
|
460
|
-
export type PreloadRouteFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory> = <TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string | undefined = undefined, TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = ''>(opts: NavigateOptions<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<Array<AnyRouteMatch> | undefined>;
|
|
460
|
+
export type PreloadRouteFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory> = <TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string | undefined = undefined, TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = ''>(opts: NavigateOptions<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>, TFrom, TTo, TMaskFrom, TMaskTo> & {}) => Promise<Array<AnyRouteMatch> | undefined>;
|
|
461
461
|
export type MatchRouteFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string | undefined = undefined, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>['types']['allParams'];
|
|
462
462
|
export type UpdateFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory, TDehydrated extends Record<string, any>> = (newOptions: RouterConstructorOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>) => void;
|
|
463
463
|
export type InvalidateFn<TRouter extends AnyRouter> = (opts?: {
|
package/dist/esm/router.d.ts
CHANGED
|
@@ -457,7 +457,7 @@ export type RouterContextOptions<TRouteTree extends AnyRoute> = AnyContext exten
|
|
|
457
457
|
context: InferRouterContext<TRouteTree>;
|
|
458
458
|
};
|
|
459
459
|
export type RouterConstructorOptions<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory, TDehydrated extends Record<string, any>> = Omit<RouterOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>, 'context' | 'serializationAdapters' | 'defaultSsr'> & RouterContextOptions<TRouteTree>;
|
|
460
|
-
export type PreloadRouteFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory> = <TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string | undefined = undefined, TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = ''>(opts: NavigateOptions<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<Array<AnyRouteMatch> | undefined>;
|
|
460
|
+
export type PreloadRouteFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory> = <TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string | undefined = undefined, TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = ''>(opts: NavigateOptions<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>, TFrom, TTo, TMaskFrom, TMaskTo> & {}) => Promise<Array<AnyRouteMatch> | undefined>;
|
|
461
461
|
export type MatchRouteFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string | undefined = undefined, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>['types']['allParams'];
|
|
462
462
|
export type UpdateFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory, TDehydrated extends Record<string, any>> = (newOptions: RouterConstructorOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>) => void;
|
|
463
463
|
export type InvalidateFn<TRouter extends AnyRouter> = (opts?: {
|
package/dist/esm/router.js
CHANGED
|
@@ -41,6 +41,10 @@ function getLocationChangeInfo(routerState) {
|
|
|
41
41
|
const hashChanged = fromLocation?.hash !== toLocation.hash;
|
|
42
42
|
return { fromLocation, toLocation, pathChanged, hrefChanged, hashChanged };
|
|
43
43
|
}
|
|
44
|
+
function filterRedirectedCachedMatches(matches) {
|
|
45
|
+
const filtered = matches.filter((d) => d.status !== "redirected");
|
|
46
|
+
return filtered.length === matches.length ? matches : filtered;
|
|
47
|
+
}
|
|
44
48
|
function createServerStore(initialState) {
|
|
45
49
|
const store = {
|
|
46
50
|
state: initialState,
|
|
@@ -131,16 +135,7 @@ class RouterCore {
|
|
|
131
135
|
getInitialRouterState(this.latestLocation)
|
|
132
136
|
);
|
|
133
137
|
} else {
|
|
134
|
-
this.__store = new Store(getInitialRouterState(this.latestLocation)
|
|
135
|
-
onUpdate: () => {
|
|
136
|
-
this.__store.state = {
|
|
137
|
-
...this.state,
|
|
138
|
-
cachedMatches: this.state.cachedMatches.filter(
|
|
139
|
-
(d) => !["redirected"].includes(d.status)
|
|
140
|
-
)
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
});
|
|
138
|
+
this.__store = new Store(getInitialRouterState(this.latestLocation));
|
|
144
139
|
setupScrollRestoration(this);
|
|
145
140
|
}
|
|
146
141
|
}
|
|
@@ -170,10 +165,10 @@ class RouterCore {
|
|
|
170
165
|
needsLocationUpdate = true;
|
|
171
166
|
}
|
|
172
167
|
if (needsLocationUpdate && this.__store) {
|
|
173
|
-
this.__store.
|
|
174
|
-
...
|
|
168
|
+
this.__store.setState((s) => ({
|
|
169
|
+
...s,
|
|
175
170
|
location: this.latestLocation
|
|
176
|
-
};
|
|
171
|
+
}));
|
|
177
172
|
}
|
|
178
173
|
if (typeof window !== "undefined" && "CSS" in window && typeof window.CSS?.supports === "function") {
|
|
179
174
|
this.isViewTransitionTypesSupported = window.CSS.supports(
|
|
@@ -767,7 +762,7 @@ class RouterCore {
|
|
|
767
762
|
cachedMatches: [
|
|
768
763
|
...s.cachedMatches,
|
|
769
764
|
...exitingMatches.filter(
|
|
770
|
-
(d) => d.status !== "error" && d.status !== "notFound"
|
|
765
|
+
(d) => d.status !== "error" && d.status !== "notFound" && d.status !== "redirected"
|
|
771
766
|
)
|
|
772
767
|
]
|
|
773
768
|
};
|
|
@@ -868,12 +863,21 @@ class RouterCore {
|
|
|
868
863
|
this.startTransition(() => {
|
|
869
864
|
const matchesKey = this.state.pendingMatches?.some((d) => d.id === id) ? "pendingMatches" : this.state.matches.some((d) => d.id === id) ? "matches" : this.state.cachedMatches.some((d) => d.id === id) ? "cachedMatches" : "";
|
|
870
865
|
if (matchesKey) {
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
866
|
+
if (matchesKey === "cachedMatches") {
|
|
867
|
+
this.__store.setState((s) => ({
|
|
868
|
+
...s,
|
|
869
|
+
cachedMatches: filterRedirectedCachedMatches(
|
|
870
|
+
s.cachedMatches.map((d) => d.id === id ? updater(d) : d)
|
|
871
|
+
)
|
|
872
|
+
}));
|
|
873
|
+
} else {
|
|
874
|
+
this.__store.setState((s) => ({
|
|
875
|
+
...s,
|
|
876
|
+
[matchesKey]: s[matchesKey]?.map(
|
|
877
|
+
(d) => d.id === id ? updater(d) : d
|
|
878
|
+
)
|
|
879
|
+
}));
|
|
880
|
+
}
|
|
877
881
|
}
|
|
878
882
|
});
|
|
879
883
|
};
|
|
@@ -969,7 +973,7 @@ class RouterCore {
|
|
|
969
973
|
};
|
|
970
974
|
this.loadRouteChunk = loadRouteChunk;
|
|
971
975
|
this.preloadRoute = async (opts) => {
|
|
972
|
-
const next = this.buildLocation(opts);
|
|
976
|
+
const next = opts._builtLocation ?? this.buildLocation(opts);
|
|
973
977
|
let matches = this.matchRoutes(next, {
|
|
974
978
|
throwOnError: true,
|
|
975
979
|
preload: true,
|