@tanstack/react-router 1.22.5 → 1.22.6
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/CatchBoundary.cjs +1 -2
- package/dist/cjs/CatchBoundary.cjs.map +1 -1
- package/dist/cjs/Matches.cjs +12 -18
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +15 -15
- package/dist/cjs/RouterProvider.cjs +16 -15
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/RouterProvider.d.cts +6 -6
- package/dist/cjs/awaited.cjs +1 -1
- package/dist/cjs/awaited.cjs.map +1 -1
- package/dist/cjs/awaited.d.cts +1 -1
- package/dist/cjs/defer.cjs.map +1 -1
- package/dist/cjs/fileRoute.cjs +1 -1
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +17 -17
- package/dist/cjs/lazyRouteComponent.cjs.map +1 -1
- package/dist/cjs/lazyRouteComponent.d.cts +1 -1
- package/dist/cjs/link.cjs +10 -11
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +16 -13
- package/dist/cjs/location.d.cts +2 -2
- package/dist/cjs/not-found.cjs.map +1 -1
- package/dist/cjs/not-found.d.cts +2 -2
- package/dist/cjs/path.cjs +2 -2
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/path.d.cts +4 -4
- package/dist/cjs/qss.cjs +4 -3
- package/dist/cjs/qss.cjs.map +1 -1
- package/dist/cjs/redirects.cjs.map +1 -1
- package/dist/cjs/redirects.d.cts +5 -5
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +34 -36
- package/dist/cjs/routeInfo.d.cts +5 -5
- package/dist/cjs/router.cjs +63 -66
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +28 -28
- package/dist/cjs/routerContext.cjs +1 -1
- package/dist/cjs/routerContext.cjs.map +1 -1
- package/dist/cjs/routerContext.d.cts +1 -1
- package/dist/cjs/scroll-restoration.cjs +7 -9
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.d.cts +1 -1
- package/dist/cjs/searchParams.cjs +10 -12
- package/dist/cjs/searchParams.cjs.map +1 -1
- package/dist/cjs/searchParams.d.cts +1 -1
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/cjs/useBlocker.d.cts +2 -2
- package/dist/cjs/useNavigate.cjs +1 -1
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useNavigate.d.cts +4 -4
- package/dist/cjs/useParams.cjs +1 -1
- package/dist/cjs/useParams.cjs.map +1 -1
- package/dist/cjs/useParams.d.cts +5 -5
- package/dist/cjs/useRouteContext.cjs +1 -1
- package/dist/cjs/useRouteContext.cjs.map +1 -1
- package/dist/cjs/useRouteContext.d.cts +4 -4
- package/dist/cjs/useRouter.cjs.map +1 -1
- package/dist/cjs/useRouter.d.cts +2 -2
- package/dist/cjs/useRouterState.cjs.map +1 -1
- package/dist/cjs/useRouterState.d.cts +2 -2
- package/dist/cjs/useSearch.cjs +1 -1
- package/dist/cjs/useSearch.cjs.map +1 -1
- package/dist/cjs/useSearch.d.cts +4 -4
- package/dist/cjs/utils.cjs +2 -2
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +13 -11
- package/dist/esm/CatchBoundary.js +1 -2
- package/dist/esm/CatchBoundary.js.map +1 -1
- package/dist/esm/Matches.d.ts +15 -15
- package/dist/esm/Matches.js +12 -18
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.d.ts +6 -6
- package/dist/esm/RouterProvider.js +16 -15
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/awaited.d.ts +1 -1
- package/dist/esm/awaited.js +1 -1
- package/dist/esm/awaited.js.map +1 -1
- package/dist/esm/defer.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +17 -17
- package/dist/esm/fileRoute.js +1 -1
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/lazyRouteComponent.d.ts +1 -1
- package/dist/esm/lazyRouteComponent.js.map +1 -1
- package/dist/esm/link.d.ts +16 -13
- package/dist/esm/link.js +10 -11
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/location.d.ts +2 -2
- package/dist/esm/not-found.d.ts +2 -2
- package/dist/esm/not-found.js.map +1 -1
- package/dist/esm/path.d.ts +4 -4
- package/dist/esm/path.js +2 -2
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/qss.js +4 -3
- package/dist/esm/qss.js.map +1 -1
- package/dist/esm/redirects.d.ts +5 -5
- package/dist/esm/redirects.js.map +1 -1
- package/dist/esm/route.d.ts +34 -36
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/routeInfo.d.ts +5 -5
- package/dist/esm/router.d.ts +28 -28
- package/dist/esm/router.js +63 -66
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/routerContext.d.ts +1 -1
- package/dist/esm/routerContext.js +1 -1
- package/dist/esm/routerContext.js.map +1 -1
- package/dist/esm/scroll-restoration.d.ts +1 -1
- package/dist/esm/scroll-restoration.js +7 -9
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/searchParams.d.ts +1 -1
- package/dist/esm/searchParams.js +10 -12
- package/dist/esm/searchParams.js.map +1 -1
- package/dist/esm/useBlocker.d.ts +2 -2
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/esm/useNavigate.d.ts +4 -4
- package/dist/esm/useNavigate.js +1 -1
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useParams.d.ts +5 -5
- package/dist/esm/useParams.js +1 -1
- package/dist/esm/useParams.js.map +1 -1
- package/dist/esm/useRouteContext.d.ts +4 -4
- package/dist/esm/useRouteContext.js +1 -1
- package/dist/esm/useRouteContext.js.map +1 -1
- package/dist/esm/useRouter.d.ts +2 -2
- package/dist/esm/useRouter.js.map +1 -1
- package/dist/esm/useRouterState.d.ts +2 -2
- package/dist/esm/useRouterState.js.map +1 -1
- package/dist/esm/useSearch.d.ts +4 -4
- package/dist/esm/useSearch.js +1 -1
- package/dist/esm/useSearch.js.map +1 -1
- package/dist/esm/utils.d.ts +13 -11
- package/dist/esm/utils.js +2 -2
- package/dist/esm/utils.js.map +1 -1
- package/package.json +3 -2
- package/src/CatchBoundary.tsx +1 -1
- package/src/Matches.tsx +41 -48
- package/src/RouterProvider.tsx +22 -16
- package/src/awaited.tsx +3 -3
- package/src/defer.ts +1 -0
- package/src/fileRoute.ts +53 -53
- package/src/history.ts +1 -1
- package/src/lazyRouteComponent.tsx +2 -1
- package/src/link.tsx +50 -42
- package/src/location.ts +2 -2
- package/src/not-found.tsx +3 -2
- package/src/path.ts +8 -8
- package/src/qss.ts +4 -5
- package/src/redirects.ts +5 -5
- package/src/route.ts +73 -67
- package/src/routeInfo.ts +8 -6
- package/src/router.ts +150 -145
- package/src/routerContext.tsx +2 -2
- package/src/scroll-restoration.tsx +9 -12
- package/src/searchParams.ts +11 -13
- package/src/useBlocker.tsx +3 -3
- package/src/useNavigate.tsx +7 -5
- package/src/useParams.tsx +6 -6
- package/src/useRouteContext.ts +7 -8
- package/src/useRouter.tsx +2 -2
- package/src/useRouterState.tsx +2 -2
- package/src/useSearch.tsx +7 -6
- package/src/utils.ts +36 -24
package/dist/esm/router.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { HistoryState, RouterHistory } from '@tanstack/history';
|
|
3
1
|
import { Store } from '@tanstack/react-store';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
2
|
+
import type * as React from 'react';
|
|
3
|
+
import type { HistoryState, RouterHistory } from '@tanstack/history';
|
|
4
|
+
import type { AnyContext, AnyRoute, AnySearchSchema, NotFoundRouteComponent, RouteMask } from './route.js';
|
|
5
|
+
import type { FullSearchSchema, RouteById, RoutePaths, RoutesById, RoutesByPath } from './routeInfo.js';
|
|
6
|
+
import type { NonNullableUpdater, PickAsRequired, Timeout, Updater } from './utils.js';
|
|
7
|
+
import type { RouteComponent } from './route.js';
|
|
8
|
+
import type { AnyRouteMatch, MatchRouteOptions, RouteMatch } from './Matches.js';
|
|
9
|
+
import type { ParsedLocation } from './location.js';
|
|
10
|
+
import type { SearchParser, SearchSerializer } from './searchParams.js';
|
|
11
|
+
import type { BuildLocationFn, CommitLocationOptions, InjectedHtmlEntry, NavigateFn } from './RouterProvider.js';
|
|
12
|
+
import type { AnyRedirect, ResolvedRedirect } from './redirects.js';
|
|
13
|
+
import type { NotFoundError } from './not-found.js';
|
|
14
|
+
import type { NavigateOptions, ResolveRelativePath, ToOptions } from './link.js';
|
|
15
|
+
import type { NoInfer } from '@tanstack/react-store';
|
|
16
|
+
import type { DeferredPromiseState } from './defer.js';
|
|
17
17
|
declare global {
|
|
18
18
|
interface Window {
|
|
19
19
|
__TSR_DEHYDRATED__?: {
|
|
@@ -59,7 +59,7 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TDehydrated extends
|
|
|
59
59
|
context?: TRouteTree['types']['routerContext'];
|
|
60
60
|
dehydrate?: () => TDehydrated;
|
|
61
61
|
hydrate?: (dehydrated: TDehydrated) => void;
|
|
62
|
-
routeMasks?: RouteMask<TRouteTree
|
|
62
|
+
routeMasks?: Array<RouteMask<TRouteTree>>;
|
|
63
63
|
unmaskOnReload?: boolean;
|
|
64
64
|
Wrap?: (props: {
|
|
65
65
|
children: any;
|
|
@@ -89,9 +89,9 @@ export interface RouterState<TRouteTree extends AnyRoute = AnyRoute> {
|
|
|
89
89
|
status: 'pending' | 'idle';
|
|
90
90
|
isLoading: boolean;
|
|
91
91
|
isTransitioning: boolean;
|
|
92
|
-
matches: RouteMatch<TRouteTree
|
|
93
|
-
pendingMatches?: RouteMatch<TRouteTree
|
|
94
|
-
cachedMatches: RouteMatch<TRouteTree
|
|
92
|
+
matches: Array<RouteMatch<TRouteTree>>;
|
|
93
|
+
pendingMatches?: Array<RouteMatch<TRouteTree>>;
|
|
94
|
+
cachedMatches: Array<RouteMatch<TRouteTree>>;
|
|
95
95
|
location: ParsedLocation<FullSearchSchema<TRouteTree>>;
|
|
96
96
|
resolvedLocation: ParsedLocation<FullSearchSchema<TRouteTree>>;
|
|
97
97
|
lastUpdated: number;
|
|
@@ -116,7 +116,7 @@ export interface BuildNextOptions {
|
|
|
116
116
|
from?: string;
|
|
117
117
|
}
|
|
118
118
|
export interface DehydratedRouterState {
|
|
119
|
-
dehydratedMatches: DehydratedRouteMatch
|
|
119
|
+
dehydratedMatches: Array<DehydratedRouteMatch>;
|
|
120
120
|
}
|
|
121
121
|
export type DehydratedRouteMatch = Pick<RouteMatch, 'id' | 'status' | 'updatedAt' | 'loaderData'>;
|
|
122
122
|
export interface DehydratedRouter {
|
|
@@ -156,7 +156,7 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
|
|
|
156
156
|
navigateTimeout: Timeout | null;
|
|
157
157
|
latestLoadPromise: Promise<void>;
|
|
158
158
|
subscribers: Set<RouterListener<RouterEvent>>;
|
|
159
|
-
injectedHtml: InjectedHtmlEntry
|
|
159
|
+
injectedHtml: Array<InjectedHtmlEntry>;
|
|
160
160
|
dehydratedData?: TDehydrated;
|
|
161
161
|
__store: Store<RouterState<TRouteTree>>;
|
|
162
162
|
options: PickAsRequired<Omit<RouterOptions<TRouteTree, TDehydrated, TSerializedError>, 'transformer'> & {
|
|
@@ -168,7 +168,7 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
|
|
|
168
168
|
routeTree: TRouteTree;
|
|
169
169
|
routesById: RoutesById<TRouteTree>;
|
|
170
170
|
routesByPath: RoutesByPath<TRouteTree>;
|
|
171
|
-
flatRoutes: AnyRoute
|
|
171
|
+
flatRoutes: Array<AnyRoute>;
|
|
172
172
|
/**
|
|
173
173
|
* @deprecated Use the `createRouter` function instead
|
|
174
174
|
*/
|
|
@@ -197,14 +197,14 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
|
|
|
197
197
|
loadMatches: ({ checkLatest, location, matches, preload, }: {
|
|
198
198
|
checkLatest: () => Promise<void> | undefined;
|
|
199
199
|
location: ParsedLocation;
|
|
200
|
-
matches: AnyRouteMatch
|
|
200
|
+
matches: Array<AnyRouteMatch>;
|
|
201
201
|
preload?: boolean | undefined;
|
|
202
|
-
}) => Promise<RouteMatch
|
|
202
|
+
}) => Promise<Array<RouteMatch>>;
|
|
203
203
|
invalidate: () => void;
|
|
204
204
|
load: () => Promise<void>;
|
|
205
205
|
resolveRedirect: (err: AnyRedirect) => ResolvedRedirect;
|
|
206
206
|
cleanCache: () => void;
|
|
207
|
-
preloadRoute: <TFrom extends string | import("./routeInfo").ParseRoute<TRouteTree, TRouteTree>["fullPath"] = string, TTo extends string = "", TMaskFrom extends string | import("./routeInfo").ParseRoute<TRouteTree, TRouteTree>["fullPath"] = TFrom, TMaskTo extends string = "">(opts: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<AnyRouteMatch
|
|
207
|
+
preloadRoute: <TFrom extends string | import("./routeInfo").ParseRoute<TRouteTree, TRouteTree>["fullPath"] = string, TTo extends string = "", TMaskFrom extends string | import("./routeInfo").ParseRoute<TRouteTree, TRouteTree>["fullPath"] = TFrom, TMaskTo extends string = "">(opts: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<Array<AnyRouteMatch> | undefined>;
|
|
208
208
|
matchRoute: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "", TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<TRouteTree, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>["types"]["allParams"];
|
|
209
209
|
injectHtml: (html: string | (() => Promise<string> | string)) => Promise<void>;
|
|
210
210
|
registeredDeferredsIds: Map<string, {}>;
|
|
@@ -217,13 +217,13 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
|
|
|
217
217
|
/**
|
|
218
218
|
* @deprecated Please extract your own data from scripts injected using the `injectHtml` method
|
|
219
219
|
*/
|
|
220
|
-
hydrateData: <T
|
|
220
|
+
hydrateData: <T = unknown>(key: any) => T | undefined;
|
|
221
221
|
dehydrate: () => DehydratedRouter;
|
|
222
222
|
hydrate: (__do_not_use_server_ctx?: string) => Promise<void>;
|
|
223
|
-
handleNotFound: (matches: AnyRouteMatch
|
|
223
|
+
handleNotFound: (matches: Array<AnyRouteMatch>, err: NotFoundError) => void;
|
|
224
224
|
hasNotFoundMatch: () => boolean;
|
|
225
225
|
}
|
|
226
|
-
export declare function lazyFn<T extends Record<string, (...args: any
|
|
226
|
+
export declare function lazyFn<T extends Record<string, (...args: Array<any>) => any>, TKey extends keyof T = 'default'>(fn: () => Promise<T>, key?: TKey): (...args: Parameters<T[TKey]>) => Promise<Awaited<ReturnType<T[TKey]>>>;
|
|
227
227
|
export declare class SearchParamError extends Error {
|
|
228
228
|
}
|
|
229
229
|
export declare class PathParamError extends Error {
|
package/dist/esm/router.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createBrowserHistory, createMemoryHistory } from "@tanstack/history";
|
|
2
2
|
import { Store } from "@tanstack/react-store";
|
|
3
|
+
import invariant from "tiny-invariant";
|
|
4
|
+
import warning from "tiny-warning";
|
|
3
5
|
import { rootRouteId } from "./route.js";
|
|
4
6
|
import { defaultStringifySearch, defaultParseSearch } from "./searchParams.js";
|
|
5
7
|
import { replaceEqualDeep, pick, isServer, deepEqual, escapeJSON, last, functionalUpdate } from "./utils.js";
|
|
6
8
|
import { getRouteMatch } from "./RouterProvider.js";
|
|
7
9
|
import { trimPath, trimPathLeft, parsePathname, resolvePath, cleanPath, matchPathname, trimPathRight, interpolatePath, joinPaths } from "./path.js";
|
|
8
|
-
import invariant from "tiny-invariant";
|
|
9
10
|
import { isRedirect } from "./redirects.js";
|
|
10
11
|
import { isNotFound } from "./not-found.js";
|
|
11
|
-
import warning from "tiny-warning";
|
|
12
12
|
const componentTypes = [
|
|
13
13
|
"component",
|
|
14
14
|
"errorComponent",
|
|
@@ -50,7 +50,10 @@ class Router {
|
|
|
50
50
|
this.basepath = `/${trimPath(newOptions.basepath)}`;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
if (
|
|
53
|
+
if (
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
55
|
+
!this.history || this.options.history && this.options.history !== this.history
|
|
56
|
+
) {
|
|
54
57
|
this.history = this.options.history ?? (typeof document !== "undefined" ? createBrowserHistory() : createMemoryHistory({
|
|
55
58
|
initialEntries: [this.options.basepath || "/"]
|
|
56
59
|
}));
|
|
@@ -105,7 +108,8 @@ class Router {
|
|
|
105
108
|
};
|
|
106
109
|
recurseRoutes([this.routeTree]);
|
|
107
110
|
const scoredRoutes = [];
|
|
108
|
-
Object.values(this.routesById)
|
|
111
|
+
const routes = Object.values(this.routesById);
|
|
112
|
+
routes.forEach((d, i) => {
|
|
109
113
|
var _a;
|
|
110
114
|
if (d.isRoot || !d.path) {
|
|
111
115
|
return;
|
|
@@ -115,14 +119,14 @@ class Router {
|
|
|
115
119
|
while (parsed.length > 1 && ((_a = parsed[0]) == null ? void 0 : _a.value) === "/") {
|
|
116
120
|
parsed.shift();
|
|
117
121
|
}
|
|
118
|
-
const scores = parsed.map((
|
|
119
|
-
if (
|
|
122
|
+
const scores = parsed.map((segment) => {
|
|
123
|
+
if (segment.value === "/") {
|
|
120
124
|
return 0.75;
|
|
121
125
|
}
|
|
122
|
-
if (
|
|
126
|
+
if (segment.type === "param") {
|
|
123
127
|
return 0.5;
|
|
124
128
|
}
|
|
125
|
-
if (
|
|
129
|
+
if (segment.type === "wildcard") {
|
|
126
130
|
return 0.25;
|
|
127
131
|
}
|
|
128
132
|
return 1;
|
|
@@ -189,7 +193,7 @@ class Router {
|
|
|
189
193
|
};
|
|
190
194
|
};
|
|
191
195
|
const location = parse(this.history.location);
|
|
192
|
-
|
|
196
|
+
const { __tempLocation, __tempKey } = location.state;
|
|
193
197
|
if (__tempLocation && (!__tempKey || __tempKey === this.tempLocationKey)) {
|
|
194
198
|
const parsedTempLocation = parse(__tempLocation);
|
|
195
199
|
parsedTempLocation.state.key = location.state.key;
|
|
@@ -206,7 +210,7 @@ class Router {
|
|
|
206
210
|
};
|
|
207
211
|
this.matchRoutes = (pathname, locationSearch, opts) => {
|
|
208
212
|
let routeParams = {};
|
|
209
|
-
|
|
213
|
+
const foundRoute = this.flatRoutes.find((route) => {
|
|
210
214
|
const matchedParams = matchPathname(
|
|
211
215
|
this.basepath,
|
|
212
216
|
trimPathRight(pathname),
|
|
@@ -223,7 +227,7 @@ class Router {
|
|
|
223
227
|
return false;
|
|
224
228
|
});
|
|
225
229
|
let routeCursor = foundRoute || this.routesById[rootRouteId];
|
|
226
|
-
|
|
230
|
+
const matchedRoutes = [routeCursor];
|
|
227
231
|
let isGlobalNotFound = false;
|
|
228
232
|
if (
|
|
229
233
|
// If we found a route, and it's not an index route and we have left over path
|
|
@@ -238,10 +242,9 @@ class Router {
|
|
|
238
242
|
isGlobalNotFound = true;
|
|
239
243
|
}
|
|
240
244
|
}
|
|
241
|
-
while (routeCursor
|
|
245
|
+
while (routeCursor.parentRoute) {
|
|
242
246
|
routeCursor = routeCursor.parentRoute;
|
|
243
|
-
|
|
244
|
-
matchedRoutes.unshift(routeCursor);
|
|
247
|
+
matchedRoutes.unshift(routeCursor);
|
|
245
248
|
}
|
|
246
249
|
const globalNotFoundRouteId = (() => {
|
|
247
250
|
if (!isGlobalNotFound) {
|
|
@@ -283,7 +286,7 @@ class Router {
|
|
|
283
286
|
const parentSearch = (parentMatch == null ? void 0 : parentMatch.search) ?? locationSearch;
|
|
284
287
|
try {
|
|
285
288
|
const validator = typeof route.options.validateSearch === "object" ? route.options.validateSearch.parse : route.options.validateSearch;
|
|
286
|
-
|
|
289
|
+
const search = (validator == null ? void 0 : validator(parentSearch)) ?? {};
|
|
287
290
|
return [
|
|
288
291
|
{
|
|
289
292
|
...parentSearch,
|
|
@@ -292,13 +295,13 @@ class Router {
|
|
|
292
295
|
void 0
|
|
293
296
|
];
|
|
294
297
|
} catch (err) {
|
|
295
|
-
const
|
|
298
|
+
const searchParamError = new SearchParamError(err.message, {
|
|
296
299
|
cause: err
|
|
297
300
|
});
|
|
298
301
|
if (opts == null ? void 0 : opts.throwOnError) {
|
|
299
|
-
throw
|
|
302
|
+
throw searchParamError;
|
|
300
303
|
}
|
|
301
|
-
return [parentSearch,
|
|
304
|
+
return [parentSearch, searchParamError];
|
|
302
305
|
}
|
|
303
306
|
})();
|
|
304
307
|
const loaderDeps = ((_b = (_a = route.options).loaderDeps) == null ? void 0 : _b.call(_a, {
|
|
@@ -314,7 +317,7 @@ class Router {
|
|
|
314
317
|
params: routeParams,
|
|
315
318
|
leaveWildcards: true
|
|
316
319
|
}) + loaderDepsHash;
|
|
317
|
-
|
|
320
|
+
const existingMatch = getRouteMatch(this.state, matchId);
|
|
318
321
|
const cause = this.state.matches.find((d) => d.id === matchId) ? "stay" : "enter";
|
|
319
322
|
const match = existingMatch ? {
|
|
320
323
|
...existingMatch,
|
|
@@ -369,13 +372,16 @@ class Router {
|
|
|
369
372
|
const build = (dest = {}, matches) => {
|
|
370
373
|
var _a, _b, _c;
|
|
371
374
|
const relevantMatches = this.state.pendingMatches || this.state.matches;
|
|
372
|
-
const fromSearch = (
|
|
375
|
+
const fromSearch = (
|
|
376
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
377
|
+
((_a = relevantMatches[relevantMatches.length - 1]) == null ? void 0 : _a.search) || this.latestLocation.search
|
|
378
|
+
);
|
|
373
379
|
const fromMatches = this.matchRoutes(
|
|
374
380
|
this.latestLocation.pathname,
|
|
375
381
|
fromSearch
|
|
376
382
|
);
|
|
377
383
|
const stayingMatches = matches == null ? void 0 : matches.filter(
|
|
378
|
-
(d) => fromMatches
|
|
384
|
+
(d) => fromMatches.find((e) => e.routeId === d.routeId)
|
|
379
385
|
);
|
|
380
386
|
const fromRoute = this.looseRoutesById[(_b = last(fromMatches)) == null ? void 0 : _b.routeId];
|
|
381
387
|
let pathname = dest.to ? this.resolvePathWithBase(
|
|
@@ -401,12 +407,9 @@ class Router {
|
|
|
401
407
|
const postSearchFilters = (stayingMatches == null ? void 0 : stayingMatches.map(
|
|
402
408
|
(match) => this.looseRoutesById[match.routeId].options.postSearchFilters ?? []
|
|
403
409
|
).flat().filter(Boolean)) ?? [];
|
|
404
|
-
const preFilteredSearch =
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
) : fromSearch;
|
|
408
|
-
const destSearch = dest.search === true ? preFilteredSearch : dest.search ? functionalUpdate(dest.search, preFilteredSearch) ?? {} : (preSearchFilters == null ? void 0 : preSearchFilters.length) ? preFilteredSearch : {};
|
|
409
|
-
const postFilteredSearch = (postSearchFilters == null ? void 0 : postSearchFilters.length) ? postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
|
|
410
|
+
const preFilteredSearch = preSearchFilters.length ? preSearchFilters.reduce((prev, next) => next(prev), fromSearch) : fromSearch;
|
|
411
|
+
const destSearch = dest.search === true ? preFilteredSearch : dest.search ? functionalUpdate(dest.search, preFilteredSearch) : preSearchFilters.length ? preFilteredSearch : {};
|
|
412
|
+
const postFilteredSearch = postSearchFilters.length ? postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
|
|
410
413
|
const search = replaceEqualDeep(fromSearch, postFilteredSearch);
|
|
411
414
|
const searchStr = this.options.stringifySearch(search);
|
|
412
415
|
const hash = dest.hash === true ? this.latestLocation.hash : dest.hash ? functionalUpdate(dest.hash, this.latestLocation.hash) : void 0;
|
|
@@ -425,11 +428,11 @@ class Router {
|
|
|
425
428
|
};
|
|
426
429
|
const buildWithMatches = (dest = {}, maskedDest) => {
|
|
427
430
|
var _a;
|
|
428
|
-
|
|
431
|
+
const next = build(dest);
|
|
429
432
|
let maskedNext = maskedDest ? build(maskedDest) : void 0;
|
|
430
433
|
if (!maskedNext) {
|
|
431
434
|
let params = {};
|
|
432
|
-
|
|
435
|
+
const foundMask = (_a = this.options.routeMasks) == null ? void 0 : _a.find((d) => {
|
|
433
436
|
const match = matchPathname(this.basepath, next.pathname, {
|
|
434
437
|
to: d.from,
|
|
435
438
|
caseSensitive: false,
|
|
@@ -654,6 +657,7 @@ class Router {
|
|
|
654
657
|
const matchPromises = [];
|
|
655
658
|
validResolvedMatches.forEach((match, index) => {
|
|
656
659
|
matchPromises.push(
|
|
660
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
657
661
|
new Promise(async (resolve, reject) => {
|
|
658
662
|
var _a2;
|
|
659
663
|
const parentMatchPromise = matchPromises[index - 1];
|
|
@@ -748,12 +752,13 @@ class Router {
|
|
|
748
752
|
meta,
|
|
749
753
|
headers
|
|
750
754
|
};
|
|
751
|
-
} catch (
|
|
755
|
+
} catch (e) {
|
|
756
|
+
let error = e;
|
|
752
757
|
if (latestPromise = checkLatest())
|
|
753
758
|
return await latestPromise;
|
|
754
|
-
handleError(
|
|
759
|
+
handleError(e);
|
|
755
760
|
try {
|
|
756
|
-
(_j = (_i = route.options).onError) == null ? void 0 : _j.call(_i,
|
|
761
|
+
(_j = (_i = route.options).onError) == null ? void 0 : _j.call(_i, e);
|
|
757
762
|
} catch (onErrorError) {
|
|
758
763
|
error = onErrorError;
|
|
759
764
|
handleError(onErrorError);
|
|
@@ -768,10 +773,9 @@ class Router {
|
|
|
768
773
|
updateMatch(match);
|
|
769
774
|
};
|
|
770
775
|
const age = Date.now() - match.updatedAt;
|
|
771
|
-
|
|
772
|
-
let shouldReload;
|
|
776
|
+
const staleAge = preload ? route.options.preloadStaleTime ?? this.options.defaultPreloadStaleTime ?? 3e4 : route.options.staleTime ?? this.options.defaultStaleTime ?? 0;
|
|
773
777
|
const shouldReloadOption = route.options.shouldReload;
|
|
774
|
-
shouldReload = typeof shouldReloadOption === "function" ? shouldReloadOption(loaderContext) : shouldReloadOption;
|
|
778
|
+
const shouldReload = typeof shouldReloadOption === "function" ? shouldReloadOption(loaderContext) : shouldReloadOption;
|
|
775
779
|
matches[index] = match = {
|
|
776
780
|
...match,
|
|
777
781
|
preload: !!preload && !this.state.matches.find((d) => d.id === match.id)
|
|
@@ -944,7 +948,7 @@ class Router {
|
|
|
944
948
|
return this.latestLoadPromise;
|
|
945
949
|
};
|
|
946
950
|
this.resolveRedirect = (err) => {
|
|
947
|
-
|
|
951
|
+
const redirect = err;
|
|
948
952
|
if (!redirect.href) {
|
|
949
953
|
redirect.href = this.buildLocation(redirect).href;
|
|
950
954
|
}
|
|
@@ -966,18 +970,17 @@ class Router {
|
|
|
966
970
|
});
|
|
967
971
|
};
|
|
968
972
|
this.preloadRoute = async (opts) => {
|
|
969
|
-
|
|
970
|
-
let next = this.buildLocation(opts);
|
|
973
|
+
const next = this.buildLocation(opts);
|
|
971
974
|
let matches = this.matchRoutes(next.pathname, next.search, {
|
|
972
975
|
throwOnError: true,
|
|
973
976
|
preload: true
|
|
974
977
|
});
|
|
975
978
|
const loadedMatchIds = Object.fromEntries(
|
|
976
|
-
|
|
979
|
+
[
|
|
977
980
|
...this.state.matches,
|
|
978
981
|
...this.state.pendingMatches ?? [],
|
|
979
982
|
...this.state.cachedMatches
|
|
980
|
-
]
|
|
983
|
+
].map((d) => [d.id, true])
|
|
981
984
|
);
|
|
982
985
|
this.__store.batch(() => {
|
|
983
986
|
matches.forEach((match) => {
|
|
@@ -1017,9 +1020,6 @@ class Router {
|
|
|
1017
1020
|
return false;
|
|
1018
1021
|
}
|
|
1019
1022
|
const baseLocation = (opts == null ? void 0 : opts.pending) ? this.latestLocation : this.state.resolvedLocation;
|
|
1020
|
-
if (!baseLocation) {
|
|
1021
|
-
return false;
|
|
1022
|
-
}
|
|
1023
1023
|
const match = matchPathname(this.basepath, baseLocation.pathname, {
|
|
1024
1024
|
...opts,
|
|
1025
1025
|
to: next.pathname
|
|
@@ -1113,7 +1113,7 @@ class Router {
|
|
|
1113
1113
|
this.dehydratedData = ctx.payload;
|
|
1114
1114
|
(_c = (_b = this.options).hydrate) == null ? void 0 : _c.call(_b, ctx.payload);
|
|
1115
1115
|
const dehydratedState = ctx.router.state;
|
|
1116
|
-
|
|
1116
|
+
const matches = this.matchRoutes(
|
|
1117
1117
|
this.state.location.pathname,
|
|
1118
1118
|
this.state.location.search
|
|
1119
1119
|
).map((match) => {
|
|
@@ -1125,23 +1125,20 @@ class Router {
|
|
|
1125
1125
|
dehydratedMatch,
|
|
1126
1126
|
`Could not find a client-side match for dehydrated match with id: ${match.id}!`
|
|
1127
1127
|
);
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
};
|
|
1143
|
-
}
|
|
1144
|
-
return match;
|
|
1128
|
+
const route = this.looseRoutesById[match.routeId];
|
|
1129
|
+
const assets = dehydratedMatch.status === "notFound" || dehydratedMatch.status === "redirected" ? {} : {
|
|
1130
|
+
meta: (_b2 = (_a2 = route.options).meta) == null ? void 0 : _b2.call(_a2, {
|
|
1131
|
+
params: match.params,
|
|
1132
|
+
loaderData: dehydratedMatch.loaderData
|
|
1133
|
+
}),
|
|
1134
|
+
links: (_d = (_c2 = route.options).links) == null ? void 0 : _d.call(_c2),
|
|
1135
|
+
scripts: (_f = (_e = route.options).scripts) == null ? void 0 : _f.call(_e)
|
|
1136
|
+
};
|
|
1137
|
+
return {
|
|
1138
|
+
...match,
|
|
1139
|
+
...dehydratedMatch,
|
|
1140
|
+
...assets
|
|
1141
|
+
};
|
|
1145
1142
|
});
|
|
1146
1143
|
this.__store.setState((s) => {
|
|
1147
1144
|
return {
|
|
@@ -1157,13 +1154,13 @@ class Router {
|
|
|
1157
1154
|
);
|
|
1158
1155
|
let routeCursor = (err.global ? this.looseRoutesById[rootRouteId] : this.looseRoutesById[err.routeId]) || this.looseRoutesById[rootRouteId];
|
|
1159
1156
|
while (!routeCursor.options.notFoundComponent && !this.options.defaultNotFoundComponent && routeCursor.id !== rootRouteId) {
|
|
1160
|
-
routeCursor = routeCursor
|
|
1157
|
+
routeCursor = routeCursor.parentRoute;
|
|
1161
1158
|
invariant(
|
|
1162
1159
|
routeCursor,
|
|
1163
1160
|
"Found invalid route tree while trying to find not-found handler."
|
|
1164
1161
|
);
|
|
1165
1162
|
}
|
|
1166
|
-
|
|
1163
|
+
const match = matchesByRouteId[routeCursor.id];
|
|
1167
1164
|
invariant(match, "Could not find match for route: " + routeCursor.id);
|
|
1168
1165
|
Object.assign(match, {
|
|
1169
1166
|
status: "notFound",
|
|
@@ -1182,9 +1179,9 @@ class Router {
|
|
|
1182
1179
|
defaultPendingMinMs: 500,
|
|
1183
1180
|
context: void 0,
|
|
1184
1181
|
...options,
|
|
1185
|
-
stringifySearch:
|
|
1186
|
-
parseSearch:
|
|
1187
|
-
transformer:
|
|
1182
|
+
stringifySearch: options.stringifySearch ?? defaultStringifySearch,
|
|
1183
|
+
parseSearch: options.parseSearch ?? defaultParseSearch,
|
|
1184
|
+
transformer: options.transformer ?? JSON
|
|
1188
1185
|
});
|
|
1189
1186
|
if (typeof document !== "undefined") {
|
|
1190
1187
|
window.__TSR__ROUTER__ = this;
|