@tanstack/react-router 1.72.1 → 1.73.1
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 +29 -15
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +4 -1
- package/dist/esm/router.d.ts +4 -1
- package/dist/esm/router.js +29 -15
- package/dist/esm/router.js.map +1 -1
- package/package.json +2 -2
- package/src/router.ts +39 -23
package/dist/cjs/router.d.cts
CHANGED
|
@@ -523,7 +523,10 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
|
|
|
523
523
|
filter?: (d: MakeRouteMatch<TRouteTree>) => boolean;
|
|
524
524
|
}) => Promise<void>;
|
|
525
525
|
resolveRedirect: (err: AnyRedirect) => ResolvedRedirect;
|
|
526
|
-
|
|
526
|
+
clearCache: (opts?: {
|
|
527
|
+
filter?: (d: MakeRouteMatch<TRouteTree>) => boolean;
|
|
528
|
+
}) => void;
|
|
529
|
+
clearExpiredCache: () => void;
|
|
527
530
|
preloadRoute: <TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string | undefined = undefined, TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = "">(opts: NavigateOptions<Router<TRouteTree, TTrailingSlashOption, TDehydrated, TSerializedError>, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<Array<AnyRouteMatch> | undefined>;
|
|
528
531
|
matchRoute: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string | undefined = undefined, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<Router<TRouteTree, TTrailingSlashOption, TDehydrated, TSerializedError>, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>["types"]["allParams"];
|
|
529
532
|
dehydrate: () => DehydratedRouter;
|
package/dist/esm/router.d.ts
CHANGED
|
@@ -523,7 +523,10 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
|
|
|
523
523
|
filter?: (d: MakeRouteMatch<TRouteTree>) => boolean;
|
|
524
524
|
}) => Promise<void>;
|
|
525
525
|
resolveRedirect: (err: AnyRedirect) => ResolvedRedirect;
|
|
526
|
-
|
|
526
|
+
clearCache: (opts?: {
|
|
527
|
+
filter?: (d: MakeRouteMatch<TRouteTree>) => boolean;
|
|
528
|
+
}) => void;
|
|
529
|
+
clearExpiredCache: () => void;
|
|
527
530
|
preloadRoute: <TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string | undefined = undefined, TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = "">(opts: NavigateOptions<Router<TRouteTree, TTrailingSlashOption, TDehydrated, TSerializedError>, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<Array<AnyRouteMatch> | undefined>;
|
|
528
531
|
matchRoute: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string | undefined = undefined, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<Router<TRouteTree, TTrailingSlashOption, TDehydrated, TSerializedError>, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>["types"]["allParams"];
|
|
529
532
|
dehydrate: () => DehydratedRouter;
|
package/dist/esm/router.js
CHANGED
|
@@ -633,7 +633,7 @@ class Router {
|
|
|
633
633
|
]
|
|
634
634
|
};
|
|
635
635
|
});
|
|
636
|
-
this.
|
|
636
|
+
this.clearExpiredCache();
|
|
637
637
|
});
|
|
638
638
|
[
|
|
639
639
|
[exitingMatches, "onLeave"],
|
|
@@ -1125,20 +1125,34 @@ class Router {
|
|
|
1125
1125
|
}
|
|
1126
1126
|
return redirect;
|
|
1127
1127
|
};
|
|
1128
|
-
this.
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1128
|
+
this.clearCache = (opts) => {
|
|
1129
|
+
const filter = opts == null ? void 0 : opts.filter;
|
|
1130
|
+
if (filter !== void 0) {
|
|
1131
|
+
this.__store.setState((s) => {
|
|
1132
|
+
return {
|
|
1133
|
+
...s,
|
|
1134
|
+
cachedMatches: s.cachedMatches.filter((m) => !filter(m))
|
|
1135
|
+
};
|
|
1136
|
+
});
|
|
1137
|
+
} else {
|
|
1138
|
+
this.__store.setState((s) => {
|
|
1139
|
+
return {
|
|
1140
|
+
...s,
|
|
1141
|
+
cachedMatches: []
|
|
1142
|
+
};
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
};
|
|
1146
|
+
this.clearExpiredCache = () => {
|
|
1147
|
+
const filter = (d) => {
|
|
1148
|
+
const route = this.looseRoutesById[d.routeId];
|
|
1149
|
+
if (!route.options.loader) {
|
|
1150
|
+
return true;
|
|
1151
|
+
}
|
|
1152
|
+
const gcTime = (d.preload ? route.options.preloadGcTime ?? this.options.defaultPreloadGcTime : route.options.gcTime ?? this.options.defaultGcTime) ?? 5 * 60 * 1e3;
|
|
1153
|
+
return !(d.status !== "error" && Date.now() - d.updatedAt < gcTime);
|
|
1154
|
+
};
|
|
1155
|
+
this.clearCache({ filter });
|
|
1142
1156
|
};
|
|
1143
1157
|
this.preloadRoute = async (opts) => {
|
|
1144
1158
|
const next = this.buildLocation(opts);
|