@tanstack/router-core 1.167.1 → 1.167.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/Matches.cjs +15 -12
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/config.cjs +9 -8
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/defer.cjs +37 -21
- package/dist/cjs/defer.cjs.map +1 -1
- package/dist/cjs/index.cjs +87 -89
- package/dist/cjs/isServer/client.cjs +5 -3
- package/dist/cjs/isServer/client.cjs.map +1 -1
- package/dist/cjs/isServer/development.cjs +5 -3
- package/dist/cjs/isServer/development.cjs.map +1 -1
- package/dist/cjs/isServer/server.cjs +5 -3
- package/dist/cjs/isServer/server.cjs.map +1 -1
- package/dist/cjs/link.cjs +5 -4
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/load-matches.cjs +622 -766
- package/dist/cjs/load-matches.cjs.map +1 -1
- package/dist/cjs/lru-cache.cjs +67 -64
- package/dist/cjs/lru-cache.cjs.map +1 -1
- package/dist/cjs/new-process-route-tree.cjs +707 -792
- package/dist/cjs/new-process-route-tree.cjs.map +1 -1
- package/dist/cjs/not-found.cjs +20 -7
- package/dist/cjs/not-found.cjs.map +1 -1
- package/dist/cjs/path.cjs +221 -232
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/qss.cjs +62 -28
- package/dist/cjs/qss.cjs.map +1 -1
- package/dist/cjs/redirect.cjs +44 -30
- package/dist/cjs/redirect.cjs.map +1 -1
- package/dist/cjs/rewrite.cjs +56 -56
- package/dist/cjs/rewrite.cjs.map +1 -1
- package/dist/cjs/root.cjs +6 -4
- package/dist/cjs/root.cjs.map +1 -1
- package/dist/cjs/route.cjs +96 -105
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/router.cjs +1154 -1524
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.cjs +189 -207
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/searchMiddleware.cjs +48 -37
- package/dist/cjs/searchMiddleware.cjs.map +1 -1
- package/dist/cjs/searchParams.cjs +57 -45
- package/dist/cjs/searchParams.cjs.map +1 -1
- package/dist/cjs/ssr/client.cjs +6 -8
- package/dist/cjs/ssr/constants.cjs +6 -5
- package/dist/cjs/ssr/constants.cjs.map +1 -1
- package/dist/cjs/ssr/createRequestHandler.cjs +41 -59
- package/dist/cjs/ssr/createRequestHandler.cjs.map +1 -1
- package/dist/cjs/ssr/handlerCallback.cjs +5 -4
- package/dist/cjs/ssr/handlerCallback.cjs.map +1 -1
- package/dist/cjs/ssr/headers.cjs +17 -26
- package/dist/cjs/ssr/headers.cjs.map +1 -1
- package/dist/cjs/ssr/json.cjs +8 -4
- package/dist/cjs/ssr/json.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/RawStream.cjs +268 -268
- package/dist/cjs/ssr/serializer/RawStream.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs +31 -32
- package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/seroval-plugins.cjs +12 -12
- package/dist/cjs/ssr/serializer/seroval-plugins.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/transformer.cjs +45 -41
- package/dist/cjs/ssr/serializer/transformer.cjs.map +1 -1
- package/dist/cjs/ssr/server.cjs +12 -14
- package/dist/cjs/ssr/ssr-client.cjs +173 -211
- package/dist/cjs/ssr/ssr-client.cjs.map +1 -1
- package/dist/cjs/ssr/ssr-match-id.cjs +6 -5
- package/dist/cjs/ssr/ssr-match-id.cjs.map +1 -1
- package/dist/cjs/ssr/ssr-server.cjs +266 -300
- package/dist/cjs/ssr/ssr-server.cjs.map +1 -1
- package/dist/cjs/ssr/transformStreamWithRouter.cjs +317 -337
- package/dist/cjs/ssr/transformStreamWithRouter.cjs.map +1 -1
- package/dist/cjs/ssr/tsrScript.cjs +6 -4
- package/dist/cjs/ssr/tsrScript.cjs.map +1 -1
- package/dist/cjs/utils/batch.cjs +13 -13
- package/dist/cjs/utils/batch.cjs.map +1 -1
- package/dist/cjs/utils.cjs +274 -208
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/esm/Matches.js +16 -13
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/config.js +10 -9
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/defer.js +37 -22
- package/dist/esm/defer.js.map +1 -1
- package/dist/esm/index.js +12 -82
- package/dist/esm/isServer/client.js +6 -5
- package/dist/esm/isServer/client.js.map +1 -1
- package/dist/esm/isServer/development.js +6 -5
- package/dist/esm/isServer/development.js.map +1 -1
- package/dist/esm/isServer/server.js +6 -5
- package/dist/esm/isServer/server.js.map +1 -1
- package/dist/esm/link.js +6 -5
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/load-matches.js +617 -765
- package/dist/esm/load-matches.js.map +1 -1
- package/dist/esm/lru-cache.js +68 -65
- package/dist/esm/lru-cache.js.map +1 -1
- package/dist/esm/new-process-route-tree.js +705 -797
- package/dist/esm/new-process-route-tree.js.map +1 -1
- package/dist/esm/not-found.js +21 -9
- package/dist/esm/not-found.js.map +1 -1
- package/dist/esm/path.js +220 -241
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/qss.js +63 -30
- package/dist/esm/qss.js.map +1 -1
- package/dist/esm/redirect.js +45 -34
- package/dist/esm/redirect.js.map +1 -1
- package/dist/esm/rewrite.js +57 -60
- package/dist/esm/rewrite.js.map +1 -1
- package/dist/esm/root.js +7 -5
- package/dist/esm/root.js.map +1 -1
- package/dist/esm/route.js +92 -105
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.js +1148 -1527
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/scroll-restoration.js +188 -213
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/searchMiddleware.js +48 -38
- package/dist/esm/searchMiddleware.js.map +1 -1
- package/dist/esm/searchParams.js +57 -48
- package/dist/esm/searchParams.js.map +1 -1
- package/dist/esm/ssr/client.js +1 -6
- package/dist/esm/ssr/constants.js +7 -7
- package/dist/esm/ssr/constants.js.map +1 -1
- package/dist/esm/ssr/createRequestHandler.js +39 -58
- package/dist/esm/ssr/createRequestHandler.js.map +1 -1
- package/dist/esm/ssr/handlerCallback.js +6 -5
- package/dist/esm/ssr/handlerCallback.js.map +1 -1
- package/dist/esm/ssr/headers.js +16 -26
- package/dist/esm/ssr/headers.js.map +1 -1
- package/dist/esm/ssr/json.js +9 -5
- package/dist/esm/ssr/json.js.map +1 -1
- package/dist/esm/ssr/serializer/RawStream.js +267 -273
- package/dist/esm/ssr/serializer/RawStream.js.map +1 -1
- package/dist/esm/ssr/serializer/ShallowErrorPlugin.js +31 -32
- package/dist/esm/ssr/serializer/ShallowErrorPlugin.js.map +1 -1
- package/dist/esm/ssr/serializer/seroval-plugins.js +10 -11
- package/dist/esm/ssr/serializer/seroval-plugins.js.map +1 -1
- package/dist/esm/ssr/serializer/transformer.js +44 -43
- package/dist/esm/ssr/serializer/transformer.js.map +1 -1
- package/dist/esm/ssr/server.js +2 -12
- package/dist/esm/ssr/ssr-client.js +169 -209
- package/dist/esm/ssr/ssr-client.js.map +1 -1
- package/dist/esm/ssr/ssr-match-id.js +7 -7
- package/dist/esm/ssr/ssr-match-id.js.map +1 -1
- package/dist/esm/ssr/ssr-server.js +262 -300
- package/dist/esm/ssr/ssr-server.js.map +1 -1
- package/dist/esm/ssr/transformStreamWithRouter.js +315 -338
- package/dist/esm/ssr/transformStreamWithRouter.js.map +1 -1
- package/dist/esm/ssr/tsrScript.js +6 -5
- package/dist/esm/ssr/tsrScript.js.map +1 -1
- package/dist/esm/utils/batch.js +13 -14
- package/dist/esm/utils/batch.js.map +1 -1
- package/dist/esm/utils.js +273 -224
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/load-matches.ts +4 -1
- package/src/router.ts +2 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/ssr/client.cjs.map +0 -1
- package/dist/cjs/ssr/server.cjs.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/ssr/client.js.map +0 -1
- package/dist/esm/ssr/server.js.map +0 -1
package/dist/esm/router.js
CHANGED
|
@@ -1,1557 +1,1178 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { isServer } from "@tanstack/router-core/isServer";
|
|
4
|
-
import { batch } from "./utils/batch.js";
|
|
5
|
-
import { createControlledPromise, isDangerousProtocol, deepEqual, DEFAULT_PROTOCOL_ALLOWLIST, nullReplaceEqualDeep, replaceEqualDeep, last, decodePath, functionalUpdate, findLast, encodePathLikeUrl } from "./utils.js";
|
|
6
|
-
import { processRouteTree, processRouteMasks, findSingleMatch, findRouteMatch, findFlatMatch } from "./new-process-route-tree.js";
|
|
7
|
-
import { compileDecodeCharMap, trimPath, resolvePath, cleanPath, trimPathRight, interpolatePath } from "./path.js";
|
|
1
|
+
import { batch as batch$1 } from "./utils/batch.js";
|
|
2
|
+
import { DEFAULT_PROTOCOL_ALLOWLIST, createControlledPromise, decodePath, deepEqual, encodePathLikeUrl, findLast, functionalUpdate, isDangerousProtocol, last, nullReplaceEqualDeep, replaceEqualDeep } from "./utils.js";
|
|
8
3
|
import { createLRUCache } from "./lru-cache.js";
|
|
4
|
+
import { findFlatMatch, findRouteMatch, findSingleMatch, processRouteMasks, processRouteTree } from "./new-process-route-tree.js";
|
|
5
|
+
import { cleanPath, compileDecodeCharMap, interpolatePath, resolvePath, trimPath, trimPathRight } from "./path.js";
|
|
9
6
|
import { isNotFound } from "./not-found.js";
|
|
10
7
|
import { setupScrollRestoration } from "./scroll-restoration.js";
|
|
11
8
|
import { defaultParseSearch, defaultStringifySearch } from "./searchParams.js";
|
|
12
9
|
import { rootRouteId } from "./root.js";
|
|
13
|
-
import {
|
|
10
|
+
import { isRedirect, redirect } from "./redirect.js";
|
|
14
11
|
import { loadMatches, loadRouteChunk, routeNeedsPreload } from "./load-matches.js";
|
|
15
|
-
import {
|
|
12
|
+
import { composeRewrites, executeRewriteInput, executeRewriteOutput, rewriteBasepath } from "./rewrite.js";
|
|
13
|
+
import { createStore } from "@tanstack/store";
|
|
14
|
+
import { createBrowserHistory, parseHref } from "@tanstack/history";
|
|
15
|
+
import { isServer } from "@tanstack/router-core/isServer";
|
|
16
|
+
//#region src/router.ts
|
|
17
|
+
/**
|
|
18
|
+
* Convert an unknown error into a minimal, serializable object.
|
|
19
|
+
* Includes name and message (and stack in development).
|
|
20
|
+
*/
|
|
16
21
|
function defaultSerializeError(err) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
data: err
|
|
29
|
-
};
|
|
22
|
+
if (err instanceof Error) {
|
|
23
|
+
const obj = {
|
|
24
|
+
name: err.name,
|
|
25
|
+
message: err.message
|
|
26
|
+
};
|
|
27
|
+
if (process.env.NODE_ENV === "development") obj.stack = err.stack;
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
30
|
+
return { data: err };
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
/** Options for configuring trailing-slash behavior. */
|
|
33
|
+
var trailingSlashOptions = {
|
|
34
|
+
always: "always",
|
|
35
|
+
never: "never",
|
|
36
|
+
preserve: "preserve"
|
|
35
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* Compute whether path, href or hash changed between previous and current
|
|
40
|
+
* resolved locations in router state.
|
|
41
|
+
*/
|
|
36
42
|
function getLocationChangeInfo(routerState) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
const fromLocation = routerState.resolvedLocation;
|
|
44
|
+
const toLocation = routerState.location;
|
|
45
|
+
return {
|
|
46
|
+
fromLocation,
|
|
47
|
+
toLocation,
|
|
48
|
+
pathChanged: fromLocation?.pathname !== toLocation.pathname,
|
|
49
|
+
hrefChanged: fromLocation?.href !== toLocation.href,
|
|
50
|
+
hashChanged: fromLocation?.hash !== toLocation.hash
|
|
51
|
+
};
|
|
43
52
|
}
|
|
44
53
|
function filterRedirectedCachedMatches(matches) {
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
const filtered = matches.filter((d) => d.status !== "redirected");
|
|
55
|
+
return filtered.length === matches.length ? matches : filtered;
|
|
47
56
|
}
|
|
48
57
|
function createServerStore(initialState) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
const store = {
|
|
59
|
+
state: initialState,
|
|
60
|
+
setState: (updater) => {
|
|
61
|
+
store.state = updater(store.state);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return store;
|
|
56
65
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
} else {
|
|
1024
|
-
this.updateMatch(id, updater);
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
});
|
|
1028
|
-
return matches;
|
|
1029
|
-
} catch (err) {
|
|
1030
|
-
if (isRedirect(err)) {
|
|
1031
|
-
if (err.options.reloadDocument) {
|
|
1032
|
-
return void 0;
|
|
1033
|
-
}
|
|
1034
|
-
return await this.preloadRoute({
|
|
1035
|
-
...err.options,
|
|
1036
|
-
_fromLocation: next
|
|
1037
|
-
});
|
|
1038
|
-
}
|
|
1039
|
-
if (!isNotFound(err)) {
|
|
1040
|
-
console.error(err);
|
|
1041
|
-
}
|
|
1042
|
-
return void 0;
|
|
1043
|
-
}
|
|
1044
|
-
};
|
|
1045
|
-
this.matchRoute = (location, opts) => {
|
|
1046
|
-
const matchLocation = {
|
|
1047
|
-
...location,
|
|
1048
|
-
to: location.to ? this.resolvePathWithBase(location.from || "", location.to) : void 0,
|
|
1049
|
-
params: location.params || {},
|
|
1050
|
-
leaveParams: true
|
|
1051
|
-
};
|
|
1052
|
-
const next = this.buildLocation(matchLocation);
|
|
1053
|
-
if (opts?.pending && this.state.status !== "pending") {
|
|
1054
|
-
return false;
|
|
1055
|
-
}
|
|
1056
|
-
const pending = opts?.pending === void 0 ? !this.state.isLoading : opts.pending;
|
|
1057
|
-
const baseLocation = pending ? this.latestLocation : this.state.resolvedLocation || this.state.location;
|
|
1058
|
-
const match = findSingleMatch(
|
|
1059
|
-
next.pathname,
|
|
1060
|
-
opts?.caseSensitive ?? false,
|
|
1061
|
-
opts?.fuzzy ?? false,
|
|
1062
|
-
baseLocation.pathname,
|
|
1063
|
-
this.processedTree
|
|
1064
|
-
);
|
|
1065
|
-
if (!match) {
|
|
1066
|
-
return false;
|
|
1067
|
-
}
|
|
1068
|
-
if (location.params) {
|
|
1069
|
-
if (!deepEqual(match.rawParams, location.params, { partial: true })) {
|
|
1070
|
-
return false;
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
if (opts?.includeSearch ?? true) {
|
|
1074
|
-
return deepEqual(baseLocation.search, next.search, { partial: true }) ? match.rawParams : false;
|
|
1075
|
-
}
|
|
1076
|
-
return match.rawParams;
|
|
1077
|
-
};
|
|
1078
|
-
this.hasNotFoundMatch = () => {
|
|
1079
|
-
return this.__store.state.matches.some(
|
|
1080
|
-
(d) => d.status === "notFound" || d.globalNotFound
|
|
1081
|
-
);
|
|
1082
|
-
};
|
|
1083
|
-
this.update({
|
|
1084
|
-
defaultPreloadDelay: 50,
|
|
1085
|
-
defaultPendingMs: 1e3,
|
|
1086
|
-
defaultPendingMinMs: 500,
|
|
1087
|
-
context: void 0,
|
|
1088
|
-
...options,
|
|
1089
|
-
caseSensitive: options.caseSensitive ?? false,
|
|
1090
|
-
notFoundMode: options.notFoundMode ?? "fuzzy",
|
|
1091
|
-
stringifySearch: options.stringifySearch ?? defaultStringifySearch,
|
|
1092
|
-
parseSearch: options.parseSearch ?? defaultParseSearch,
|
|
1093
|
-
protocolAllowlist: options.protocolAllowlist ?? DEFAULT_PROTOCOL_ALLOWLIST
|
|
1094
|
-
});
|
|
1095
|
-
if (typeof document !== "undefined") {
|
|
1096
|
-
self.__TSR_ROUTER__ = this;
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
isShell() {
|
|
1100
|
-
return !!this.options.isShell;
|
|
1101
|
-
}
|
|
1102
|
-
isPrerendering() {
|
|
1103
|
-
return !!this.options.isPrerendering;
|
|
1104
|
-
}
|
|
1105
|
-
get state() {
|
|
1106
|
-
return this.__store.state;
|
|
1107
|
-
}
|
|
1108
|
-
setRoutes({
|
|
1109
|
-
routesById,
|
|
1110
|
-
routesByPath,
|
|
1111
|
-
processedTree
|
|
1112
|
-
}) {
|
|
1113
|
-
this.routesById = routesById;
|
|
1114
|
-
this.routesByPath = routesByPath;
|
|
1115
|
-
this.processedTree = processedTree;
|
|
1116
|
-
const notFoundRoute = this.options.notFoundRoute;
|
|
1117
|
-
if (notFoundRoute) {
|
|
1118
|
-
notFoundRoute.init({
|
|
1119
|
-
originalIndex: 99999999999
|
|
1120
|
-
});
|
|
1121
|
-
this.routesById[notFoundRoute.id] = notFoundRoute;
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
get looseRoutesById() {
|
|
1125
|
-
return this.routesById;
|
|
1126
|
-
}
|
|
1127
|
-
getParentContext(parentMatch) {
|
|
1128
|
-
const parentMatchId = parentMatch?.id;
|
|
1129
|
-
const parentContext = !parentMatchId ? this.options.context ?? void 0 : parentMatch.context ?? this.options.context ?? void 0;
|
|
1130
|
-
return parentContext;
|
|
1131
|
-
}
|
|
1132
|
-
matchRoutesInternal(next, opts) {
|
|
1133
|
-
const matchedRoutesResult = this.getMatchedRoutes(next.pathname);
|
|
1134
|
-
const { foundRoute, routeParams, parsedParams } = matchedRoutesResult;
|
|
1135
|
-
let { matchedRoutes } = matchedRoutesResult;
|
|
1136
|
-
let isGlobalNotFound = false;
|
|
1137
|
-
if (
|
|
1138
|
-
// If we found a route, and it's not an index route and we have left over path
|
|
1139
|
-
foundRoute ? foundRoute.path !== "/" && routeParams["**"] : (
|
|
1140
|
-
// Or if we didn't find a route and we have left over path
|
|
1141
|
-
trimPathRight(next.pathname)
|
|
1142
|
-
)
|
|
1143
|
-
) {
|
|
1144
|
-
if (this.options.notFoundRoute) {
|
|
1145
|
-
matchedRoutes = [...matchedRoutes, this.options.notFoundRoute];
|
|
1146
|
-
} else {
|
|
1147
|
-
isGlobalNotFound = true;
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
const globalNotFoundRouteId = isGlobalNotFound ? findGlobalNotFoundRouteId(this.options.notFoundMode, matchedRoutes) : void 0;
|
|
1151
|
-
const matches = new Array(matchedRoutes.length);
|
|
1152
|
-
const previousMatchesByRouteId = new Map(
|
|
1153
|
-
this.state.matches.map((match) => [match.routeId, match])
|
|
1154
|
-
);
|
|
1155
|
-
for (let index = 0; index < matchedRoutes.length; index++) {
|
|
1156
|
-
const route = matchedRoutes[index];
|
|
1157
|
-
const parentMatch = matches[index - 1];
|
|
1158
|
-
let preMatchSearch;
|
|
1159
|
-
let strictMatchSearch;
|
|
1160
|
-
let searchError;
|
|
1161
|
-
{
|
|
1162
|
-
const parentSearch = parentMatch?.search ?? next.search;
|
|
1163
|
-
const parentStrictSearch = parentMatch?._strictSearch ?? void 0;
|
|
1164
|
-
try {
|
|
1165
|
-
const strictSearch = validateSearch(route.options.validateSearch, { ...parentSearch }) ?? void 0;
|
|
1166
|
-
preMatchSearch = {
|
|
1167
|
-
...parentSearch,
|
|
1168
|
-
...strictSearch
|
|
1169
|
-
};
|
|
1170
|
-
strictMatchSearch = { ...parentStrictSearch, ...strictSearch };
|
|
1171
|
-
searchError = void 0;
|
|
1172
|
-
} catch (err) {
|
|
1173
|
-
let searchParamError = err;
|
|
1174
|
-
if (!(err instanceof SearchParamError)) {
|
|
1175
|
-
searchParamError = new SearchParamError(err.message, {
|
|
1176
|
-
cause: err
|
|
1177
|
-
});
|
|
1178
|
-
}
|
|
1179
|
-
if (opts?.throwOnError) {
|
|
1180
|
-
throw searchParamError;
|
|
1181
|
-
}
|
|
1182
|
-
preMatchSearch = parentSearch;
|
|
1183
|
-
strictMatchSearch = {};
|
|
1184
|
-
searchError = searchParamError;
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
const loaderDeps = route.options.loaderDeps?.({
|
|
1188
|
-
search: preMatchSearch
|
|
1189
|
-
}) ?? "";
|
|
1190
|
-
const loaderDepsHash = loaderDeps ? JSON.stringify(loaderDeps) : "";
|
|
1191
|
-
const { interpolatedPath, usedParams } = interpolatePath({
|
|
1192
|
-
path: route.fullPath,
|
|
1193
|
-
params: routeParams,
|
|
1194
|
-
decoder: this.pathParamsDecoder,
|
|
1195
|
-
server: this.isServer
|
|
1196
|
-
});
|
|
1197
|
-
const matchId = (
|
|
1198
|
-
// route.id for disambiguation
|
|
1199
|
-
route.id + // interpolatedPath for param changes
|
|
1200
|
-
interpolatedPath + // explicit deps
|
|
1201
|
-
loaderDepsHash
|
|
1202
|
-
);
|
|
1203
|
-
const existingMatch = this.getMatch(matchId);
|
|
1204
|
-
const previousMatch = previousMatchesByRouteId.get(route.id);
|
|
1205
|
-
const strictParams = existingMatch?._strictParams ?? usedParams;
|
|
1206
|
-
let paramsError = void 0;
|
|
1207
|
-
if (!existingMatch) {
|
|
1208
|
-
try {
|
|
1209
|
-
extractStrictParams(route, usedParams, parsedParams, strictParams);
|
|
1210
|
-
} catch (err) {
|
|
1211
|
-
if (isNotFound(err) || isRedirect(err)) {
|
|
1212
|
-
paramsError = err;
|
|
1213
|
-
} else {
|
|
1214
|
-
paramsError = new PathParamError(err.message, {
|
|
1215
|
-
cause: err
|
|
1216
|
-
});
|
|
1217
|
-
}
|
|
1218
|
-
if (opts?.throwOnError) {
|
|
1219
|
-
throw paramsError;
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
Object.assign(routeParams, strictParams);
|
|
1224
|
-
const cause = previousMatch ? "stay" : "enter";
|
|
1225
|
-
let match;
|
|
1226
|
-
if (existingMatch) {
|
|
1227
|
-
match = {
|
|
1228
|
-
...existingMatch,
|
|
1229
|
-
cause,
|
|
1230
|
-
params: previousMatch?.params ?? routeParams,
|
|
1231
|
-
_strictParams: strictParams,
|
|
1232
|
-
search: previousMatch ? nullReplaceEqualDeep(previousMatch.search, preMatchSearch) : nullReplaceEqualDeep(existingMatch.search, preMatchSearch),
|
|
1233
|
-
_strictSearch: strictMatchSearch
|
|
1234
|
-
};
|
|
1235
|
-
} else {
|
|
1236
|
-
const status = route.options.loader || route.options.beforeLoad || route.lazyFn || routeNeedsPreload(route) ? "pending" : "success";
|
|
1237
|
-
match = {
|
|
1238
|
-
id: matchId,
|
|
1239
|
-
ssr: isServer ?? this.isServer ? void 0 : route.options.ssr,
|
|
1240
|
-
index,
|
|
1241
|
-
routeId: route.id,
|
|
1242
|
-
params: previousMatch?.params ?? routeParams,
|
|
1243
|
-
_strictParams: strictParams,
|
|
1244
|
-
pathname: interpolatedPath,
|
|
1245
|
-
updatedAt: Date.now(),
|
|
1246
|
-
search: previousMatch ? nullReplaceEqualDeep(previousMatch.search, preMatchSearch) : preMatchSearch,
|
|
1247
|
-
_strictSearch: strictMatchSearch,
|
|
1248
|
-
searchError: void 0,
|
|
1249
|
-
status,
|
|
1250
|
-
isFetching: false,
|
|
1251
|
-
error: void 0,
|
|
1252
|
-
paramsError,
|
|
1253
|
-
__routeContext: void 0,
|
|
1254
|
-
_nonReactive: {
|
|
1255
|
-
loadPromise: createControlledPromise()
|
|
1256
|
-
},
|
|
1257
|
-
__beforeLoadContext: void 0,
|
|
1258
|
-
context: {},
|
|
1259
|
-
abortController: new AbortController(),
|
|
1260
|
-
fetchCount: 0,
|
|
1261
|
-
cause,
|
|
1262
|
-
loaderDeps: previousMatch ? replaceEqualDeep(previousMatch.loaderDeps, loaderDeps) : loaderDeps,
|
|
1263
|
-
invalid: false,
|
|
1264
|
-
preload: false,
|
|
1265
|
-
links: void 0,
|
|
1266
|
-
scripts: void 0,
|
|
1267
|
-
headScripts: void 0,
|
|
1268
|
-
meta: void 0,
|
|
1269
|
-
staticData: route.options.staticData || {},
|
|
1270
|
-
fullPath: route.fullPath
|
|
1271
|
-
};
|
|
1272
|
-
}
|
|
1273
|
-
if (!opts?.preload) {
|
|
1274
|
-
match.globalNotFound = globalNotFoundRouteId === route.id;
|
|
1275
|
-
}
|
|
1276
|
-
match.searchError = searchError;
|
|
1277
|
-
const parentContext = this.getParentContext(parentMatch);
|
|
1278
|
-
match.context = {
|
|
1279
|
-
...parentContext,
|
|
1280
|
-
...match.__routeContext,
|
|
1281
|
-
...match.__beforeLoadContext
|
|
1282
|
-
};
|
|
1283
|
-
matches[index] = match;
|
|
1284
|
-
}
|
|
1285
|
-
for (let index = 0; index < matches.length; index++) {
|
|
1286
|
-
const match = matches[index];
|
|
1287
|
-
const route = this.looseRoutesById[match.routeId];
|
|
1288
|
-
const existingMatch = this.getMatch(match.id);
|
|
1289
|
-
const previousMatch = previousMatchesByRouteId.get(match.routeId);
|
|
1290
|
-
match.params = previousMatch ? nullReplaceEqualDeep(previousMatch.params, routeParams) : routeParams;
|
|
1291
|
-
if (!existingMatch) {
|
|
1292
|
-
const parentMatch = matches[index - 1];
|
|
1293
|
-
const parentContext = this.getParentContext(parentMatch);
|
|
1294
|
-
if (route.options.context) {
|
|
1295
|
-
const contextFnContext = {
|
|
1296
|
-
deps: match.loaderDeps,
|
|
1297
|
-
params: match.params,
|
|
1298
|
-
context: parentContext ?? {},
|
|
1299
|
-
location: next,
|
|
1300
|
-
navigate: (opts2) => this.navigate({ ...opts2, _fromLocation: next }),
|
|
1301
|
-
buildLocation: this.buildLocation,
|
|
1302
|
-
cause: match.cause,
|
|
1303
|
-
abortController: match.abortController,
|
|
1304
|
-
preload: !!match.preload,
|
|
1305
|
-
matches,
|
|
1306
|
-
routeId: route.id
|
|
1307
|
-
};
|
|
1308
|
-
match.__routeContext = route.options.context(contextFnContext) ?? void 0;
|
|
1309
|
-
}
|
|
1310
|
-
match.context = {
|
|
1311
|
-
...parentContext,
|
|
1312
|
-
...match.__routeContext,
|
|
1313
|
-
...match.__beforeLoadContext
|
|
1314
|
-
};
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
return matches;
|
|
1318
|
-
}
|
|
1319
|
-
/**
|
|
1320
|
-
* Lightweight route matching for buildLocation.
|
|
1321
|
-
* Only computes fullPath, accumulated search, and params - skipping expensive
|
|
1322
|
-
* operations like AbortController, ControlledPromise, loaderDeps, and full match objects.
|
|
1323
|
-
*/
|
|
1324
|
-
matchRoutesLightweight(location) {
|
|
1325
|
-
const { matchedRoutes, routeParams, parsedParams } = this.getMatchedRoutes(
|
|
1326
|
-
location.pathname
|
|
1327
|
-
);
|
|
1328
|
-
const lastRoute = last(matchedRoutes);
|
|
1329
|
-
const accumulatedSearch = { ...location.search };
|
|
1330
|
-
for (const route of matchedRoutes) {
|
|
1331
|
-
try {
|
|
1332
|
-
Object.assign(
|
|
1333
|
-
accumulatedSearch,
|
|
1334
|
-
validateSearch(route.options.validateSearch, accumulatedSearch)
|
|
1335
|
-
);
|
|
1336
|
-
} catch {
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
const lastStateMatch = last(this.state.matches);
|
|
1340
|
-
const canReuseParams = lastStateMatch && lastStateMatch.routeId === lastRoute.id && location.pathname === this.state.location.pathname;
|
|
1341
|
-
let params;
|
|
1342
|
-
if (canReuseParams) {
|
|
1343
|
-
params = lastStateMatch.params;
|
|
1344
|
-
} else {
|
|
1345
|
-
const strictParams = Object.assign(
|
|
1346
|
-
/* @__PURE__ */ Object.create(null),
|
|
1347
|
-
routeParams
|
|
1348
|
-
);
|
|
1349
|
-
for (const route of matchedRoutes) {
|
|
1350
|
-
try {
|
|
1351
|
-
extractStrictParams(
|
|
1352
|
-
route,
|
|
1353
|
-
routeParams,
|
|
1354
|
-
parsedParams ?? {},
|
|
1355
|
-
strictParams
|
|
1356
|
-
);
|
|
1357
|
-
} catch {
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
params = strictParams;
|
|
1361
|
-
}
|
|
1362
|
-
return {
|
|
1363
|
-
matchedRoutes,
|
|
1364
|
-
fullPath: lastRoute.fullPath,
|
|
1365
|
-
search: accumulatedSearch,
|
|
1366
|
-
params
|
|
1367
|
-
};
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
class SearchParamError extends Error {
|
|
1371
|
-
}
|
|
1372
|
-
class PathParamError extends Error {
|
|
1373
|
-
}
|
|
1374
|
-
const normalize = (str) => str.endsWith("/") && str.length > 1 ? str.slice(0, -1) : str;
|
|
66
|
+
var RouterCore = class {
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated Use the `createRouter` function instead
|
|
69
|
+
*/
|
|
70
|
+
constructor(options) {
|
|
71
|
+
this.tempLocationKey = `${Math.round(Math.random() * 1e7)}`;
|
|
72
|
+
this.resetNextScroll = true;
|
|
73
|
+
this.shouldViewTransition = void 0;
|
|
74
|
+
this.isViewTransitionTypesSupported = void 0;
|
|
75
|
+
this.subscribers = /* @__PURE__ */ new Set();
|
|
76
|
+
this.isScrollRestoring = false;
|
|
77
|
+
this.isScrollRestorationSetup = false;
|
|
78
|
+
this.startTransition = (fn) => fn();
|
|
79
|
+
this.update = (newOptions) => {
|
|
80
|
+
if (process.env.NODE_ENV !== "production") {
|
|
81
|
+
if (newOptions.notFoundRoute) console.warn("The notFoundRoute API is deprecated and will be removed in the next major version. See https://tanstack.com/router/v1/docs/framework/react/guide/not-found-errors#migrating-from-notfoundroute for more info.");
|
|
82
|
+
}
|
|
83
|
+
const prevOptions = this.options;
|
|
84
|
+
const prevBasepath = this.basepath ?? prevOptions?.basepath ?? "/";
|
|
85
|
+
const basepathWasUnset = this.basepath === void 0;
|
|
86
|
+
const prevRewriteOption = prevOptions?.rewrite;
|
|
87
|
+
this.options = {
|
|
88
|
+
...prevOptions,
|
|
89
|
+
...newOptions
|
|
90
|
+
};
|
|
91
|
+
this.isServer = this.options.isServer ?? typeof document === "undefined";
|
|
92
|
+
this.protocolAllowlist = new Set(this.options.protocolAllowlist);
|
|
93
|
+
if (this.options.pathParamsAllowedCharacters) this.pathParamsDecoder = compileDecodeCharMap(this.options.pathParamsAllowedCharacters);
|
|
94
|
+
if (!this.history || this.options.history && this.options.history !== this.history) if (!this.options.history) {
|
|
95
|
+
if (!(isServer ?? this.isServer)) this.history = createBrowserHistory();
|
|
96
|
+
} else this.history = this.options.history;
|
|
97
|
+
this.origin = this.options.origin;
|
|
98
|
+
if (!this.origin) if (!(isServer ?? this.isServer) && window?.origin && window.origin !== "null") this.origin = window.origin;
|
|
99
|
+
else this.origin = "http://localhost";
|
|
100
|
+
if (this.history) this.updateLatestLocation();
|
|
101
|
+
if (this.options.routeTree !== this.routeTree) {
|
|
102
|
+
this.routeTree = this.options.routeTree;
|
|
103
|
+
let processRouteTreeResult;
|
|
104
|
+
if ((isServer ?? this.isServer) && process.env.NODE_ENV !== "development" && globalThis.__TSR_CACHE__ && globalThis.__TSR_CACHE__.routeTree === this.routeTree) {
|
|
105
|
+
const cached = globalThis.__TSR_CACHE__;
|
|
106
|
+
this.resolvePathCache = cached.resolvePathCache;
|
|
107
|
+
processRouteTreeResult = cached.processRouteTreeResult;
|
|
108
|
+
} else {
|
|
109
|
+
this.resolvePathCache = createLRUCache(1e3);
|
|
110
|
+
processRouteTreeResult = this.buildRouteTree();
|
|
111
|
+
if ((isServer ?? this.isServer) && process.env.NODE_ENV !== "development" && globalThis.__TSR_CACHE__ === void 0) globalThis.__TSR_CACHE__ = {
|
|
112
|
+
routeTree: this.routeTree,
|
|
113
|
+
processRouteTreeResult,
|
|
114
|
+
resolvePathCache: this.resolvePathCache
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
this.setRoutes(processRouteTreeResult);
|
|
118
|
+
}
|
|
119
|
+
if (!this.__store && this.latestLocation) if (isServer ?? this.isServer) this.__store = createServerStore(getInitialRouterState(this.latestLocation));
|
|
120
|
+
else {
|
|
121
|
+
this.__store = createStore(getInitialRouterState(this.latestLocation));
|
|
122
|
+
setupScrollRestoration(this);
|
|
123
|
+
}
|
|
124
|
+
let needsLocationUpdate = false;
|
|
125
|
+
const nextBasepath = this.options.basepath ?? "/";
|
|
126
|
+
const nextRewriteOption = this.options.rewrite;
|
|
127
|
+
if (basepathWasUnset || prevBasepath !== nextBasepath || prevRewriteOption !== nextRewriteOption) {
|
|
128
|
+
this.basepath = nextBasepath;
|
|
129
|
+
const rewrites = [];
|
|
130
|
+
const trimmed = trimPath(nextBasepath);
|
|
131
|
+
if (trimmed && trimmed !== "/") rewrites.push(rewriteBasepath({ basepath: nextBasepath }));
|
|
132
|
+
if (nextRewriteOption) rewrites.push(nextRewriteOption);
|
|
133
|
+
this.rewrite = rewrites.length === 0 ? void 0 : rewrites.length === 1 ? rewrites[0] : composeRewrites(rewrites);
|
|
134
|
+
if (this.history) this.updateLatestLocation();
|
|
135
|
+
needsLocationUpdate = true;
|
|
136
|
+
}
|
|
137
|
+
if (needsLocationUpdate && this.__store) this.__store.setState((s) => ({
|
|
138
|
+
...s,
|
|
139
|
+
location: this.latestLocation
|
|
140
|
+
}));
|
|
141
|
+
if (typeof window !== "undefined" && "CSS" in window && typeof window.CSS?.supports === "function") this.isViewTransitionTypesSupported = window.CSS.supports("selector(:active-view-transition-type(a)");
|
|
142
|
+
};
|
|
143
|
+
this.updateLatestLocation = () => {
|
|
144
|
+
this.latestLocation = this.parseLocation(this.history.location, this.latestLocation);
|
|
145
|
+
};
|
|
146
|
+
this.buildRouteTree = () => {
|
|
147
|
+
const result = processRouteTree(this.routeTree, this.options.caseSensitive, (route, i) => {
|
|
148
|
+
route.init({ originalIndex: i });
|
|
149
|
+
});
|
|
150
|
+
if (this.options.routeMasks) processRouteMasks(this.options.routeMasks, result.processedTree);
|
|
151
|
+
return result;
|
|
152
|
+
};
|
|
153
|
+
this.subscribe = (eventType, fn) => {
|
|
154
|
+
const listener = {
|
|
155
|
+
eventType,
|
|
156
|
+
fn
|
|
157
|
+
};
|
|
158
|
+
this.subscribers.add(listener);
|
|
159
|
+
return () => {
|
|
160
|
+
this.subscribers.delete(listener);
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
this.emit = (routerEvent) => {
|
|
164
|
+
this.subscribers.forEach((listener) => {
|
|
165
|
+
if (listener.eventType === routerEvent.type) listener.fn(routerEvent);
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
this.parseLocation = (locationToParse, previousLocation) => {
|
|
169
|
+
const parse = ({ pathname, search, hash, href, state }) => {
|
|
170
|
+
if (!this.rewrite && !/[ \x00-\x1f\x7f\u0080-\uffff]/.test(pathname)) {
|
|
171
|
+
const parsedSearch = this.options.parseSearch(search);
|
|
172
|
+
const searchStr = this.options.stringifySearch(parsedSearch);
|
|
173
|
+
return {
|
|
174
|
+
href: pathname + searchStr + hash,
|
|
175
|
+
publicHref: href,
|
|
176
|
+
pathname: decodePath(pathname).path,
|
|
177
|
+
external: false,
|
|
178
|
+
searchStr,
|
|
179
|
+
search: nullReplaceEqualDeep(previousLocation?.search, parsedSearch),
|
|
180
|
+
hash: decodePath(hash.slice(1)).path,
|
|
181
|
+
state: replaceEqualDeep(previousLocation?.state, state)
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
const fullUrl = new URL(href, this.origin);
|
|
185
|
+
const url = executeRewriteInput(this.rewrite, fullUrl);
|
|
186
|
+
const parsedSearch = this.options.parseSearch(url.search);
|
|
187
|
+
const searchStr = this.options.stringifySearch(parsedSearch);
|
|
188
|
+
url.search = searchStr;
|
|
189
|
+
return {
|
|
190
|
+
href: url.href.replace(url.origin, ""),
|
|
191
|
+
publicHref: href,
|
|
192
|
+
pathname: decodePath(url.pathname).path,
|
|
193
|
+
external: !!this.rewrite && url.origin !== this.origin,
|
|
194
|
+
searchStr,
|
|
195
|
+
search: nullReplaceEqualDeep(previousLocation?.search, parsedSearch),
|
|
196
|
+
hash: decodePath(url.hash.slice(1)).path,
|
|
197
|
+
state: replaceEqualDeep(previousLocation?.state, state)
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
const location = parse(locationToParse);
|
|
201
|
+
const { __tempLocation, __tempKey } = location.state;
|
|
202
|
+
if (__tempLocation && (!__tempKey || __tempKey === this.tempLocationKey)) {
|
|
203
|
+
const parsedTempLocation = parse(__tempLocation);
|
|
204
|
+
parsedTempLocation.state.key = location.state.key;
|
|
205
|
+
parsedTempLocation.state.__TSR_key = location.state.__TSR_key;
|
|
206
|
+
delete parsedTempLocation.state.__tempLocation;
|
|
207
|
+
return {
|
|
208
|
+
...parsedTempLocation,
|
|
209
|
+
maskedLocation: location
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
return location;
|
|
213
|
+
};
|
|
214
|
+
this.resolvePathWithBase = (from, path) => {
|
|
215
|
+
return resolvePath({
|
|
216
|
+
base: from,
|
|
217
|
+
to: cleanPath(path),
|
|
218
|
+
trailingSlash: this.options.trailingSlash,
|
|
219
|
+
cache: this.resolvePathCache
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
this.matchRoutes = (pathnameOrNext, locationSearchOrOpts, opts) => {
|
|
223
|
+
if (typeof pathnameOrNext === "string") return this.matchRoutesInternal({
|
|
224
|
+
pathname: pathnameOrNext,
|
|
225
|
+
search: locationSearchOrOpts
|
|
226
|
+
}, opts);
|
|
227
|
+
return this.matchRoutesInternal(pathnameOrNext, locationSearchOrOpts);
|
|
228
|
+
};
|
|
229
|
+
this.getMatchedRoutes = (pathname) => {
|
|
230
|
+
return getMatchedRoutes({
|
|
231
|
+
pathname,
|
|
232
|
+
routesById: this.routesById,
|
|
233
|
+
processedTree: this.processedTree
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
this.cancelMatch = (id) => {
|
|
237
|
+
const match = this.getMatch(id);
|
|
238
|
+
if (!match) return;
|
|
239
|
+
match.abortController.abort();
|
|
240
|
+
clearTimeout(match._nonReactive.pendingTimeout);
|
|
241
|
+
match._nonReactive.pendingTimeout = void 0;
|
|
242
|
+
};
|
|
243
|
+
this.cancelMatches = () => {
|
|
244
|
+
const currentPendingMatches = this.state.matches.filter((match) => match.status === "pending");
|
|
245
|
+
const currentLoadingMatches = this.state.matches.filter((match) => match.isFetching === "loader");
|
|
246
|
+
new Set([
|
|
247
|
+
...this.state.pendingMatches ?? [],
|
|
248
|
+
...currentPendingMatches,
|
|
249
|
+
...currentLoadingMatches
|
|
250
|
+
]).forEach((match) => {
|
|
251
|
+
this.cancelMatch(match.id);
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
this.buildLocation = (opts) => {
|
|
255
|
+
const build = (dest = {}) => {
|
|
256
|
+
const currentLocation = dest._fromLocation || this.pendingBuiltLocation || this.latestLocation;
|
|
257
|
+
const lightweightResult = this.matchRoutesLightweight(currentLocation);
|
|
258
|
+
if (dest.from && process.env.NODE_ENV !== "production" && dest._isNavigate) {
|
|
259
|
+
const allFromMatches = this.getMatchedRoutes(dest.from).matchedRoutes;
|
|
260
|
+
const matchedFrom = findLast(lightweightResult.matchedRoutes, (d) => {
|
|
261
|
+
return comparePaths(d.fullPath, dest.from);
|
|
262
|
+
});
|
|
263
|
+
const matchedCurrent = findLast(allFromMatches, (d) => {
|
|
264
|
+
return comparePaths(d.fullPath, lightweightResult.fullPath);
|
|
265
|
+
});
|
|
266
|
+
if (!matchedFrom && !matchedCurrent) console.warn(`Could not find match for from: ${dest.from}`);
|
|
267
|
+
}
|
|
268
|
+
const defaultedFromPath = dest.unsafeRelative === "path" ? currentLocation.pathname : dest.from ?? lightweightResult.fullPath;
|
|
269
|
+
const fromPath = this.resolvePathWithBase(defaultedFromPath, ".");
|
|
270
|
+
const fromSearch = lightweightResult.search;
|
|
271
|
+
const fromParams = Object.assign(Object.create(null), lightweightResult.params);
|
|
272
|
+
const nextTo = dest.to ? this.resolvePathWithBase(fromPath, `${dest.to}`) : this.resolvePathWithBase(fromPath, ".");
|
|
273
|
+
const nextParams = dest.params === false || dest.params === null ? Object.create(null) : (dest.params ?? true) === true ? fromParams : Object.assign(fromParams, functionalUpdate(dest.params, fromParams));
|
|
274
|
+
const destMatchResult = this.getMatchedRoutes(nextTo);
|
|
275
|
+
let destRoutes = destMatchResult.matchedRoutes;
|
|
276
|
+
if ((!destMatchResult.foundRoute || destMatchResult.foundRoute.path !== "/" && destMatchResult.routeParams["**"]) && this.options.notFoundRoute) destRoutes = [...destRoutes, this.options.notFoundRoute];
|
|
277
|
+
if (Object.keys(nextParams).length > 0) for (const route of destRoutes) {
|
|
278
|
+
const fn = route.options.params?.stringify ?? route.options.stringifyParams;
|
|
279
|
+
if (fn) try {
|
|
280
|
+
Object.assign(nextParams, fn(nextParams));
|
|
281
|
+
} catch {}
|
|
282
|
+
}
|
|
283
|
+
const nextPathname = opts.leaveParams ? nextTo : decodePath(interpolatePath({
|
|
284
|
+
path: nextTo,
|
|
285
|
+
params: nextParams,
|
|
286
|
+
decoder: this.pathParamsDecoder,
|
|
287
|
+
server: this.isServer
|
|
288
|
+
}).interpolatedPath).path;
|
|
289
|
+
let nextSearch = fromSearch;
|
|
290
|
+
if (opts._includeValidateSearch && this.options.search?.strict) {
|
|
291
|
+
const validatedSearch = {};
|
|
292
|
+
destRoutes.forEach((route) => {
|
|
293
|
+
if (route.options.validateSearch) try {
|
|
294
|
+
Object.assign(validatedSearch, validateSearch(route.options.validateSearch, {
|
|
295
|
+
...validatedSearch,
|
|
296
|
+
...nextSearch
|
|
297
|
+
}));
|
|
298
|
+
} catch {}
|
|
299
|
+
});
|
|
300
|
+
nextSearch = validatedSearch;
|
|
301
|
+
}
|
|
302
|
+
nextSearch = applySearchMiddleware({
|
|
303
|
+
search: nextSearch,
|
|
304
|
+
dest,
|
|
305
|
+
destRoutes,
|
|
306
|
+
_includeValidateSearch: opts._includeValidateSearch
|
|
307
|
+
});
|
|
308
|
+
nextSearch = nullReplaceEqualDeep(fromSearch, nextSearch);
|
|
309
|
+
const searchStr = this.options.stringifySearch(nextSearch);
|
|
310
|
+
const hash = dest.hash === true ? currentLocation.hash : dest.hash ? functionalUpdate(dest.hash, currentLocation.hash) : void 0;
|
|
311
|
+
const hashStr = hash ? `#${hash}` : "";
|
|
312
|
+
let nextState = dest.state === true ? currentLocation.state : dest.state ? functionalUpdate(dest.state, currentLocation.state) : {};
|
|
313
|
+
nextState = replaceEqualDeep(currentLocation.state, nextState);
|
|
314
|
+
const fullPath = `${nextPathname}${searchStr}${hashStr}`;
|
|
315
|
+
let href;
|
|
316
|
+
let publicHref;
|
|
317
|
+
let external = false;
|
|
318
|
+
if (this.rewrite) {
|
|
319
|
+
const url = new URL(fullPath, this.origin);
|
|
320
|
+
const rewrittenUrl = executeRewriteOutput(this.rewrite, url);
|
|
321
|
+
href = url.href.replace(url.origin, "");
|
|
322
|
+
if (rewrittenUrl.origin !== this.origin) {
|
|
323
|
+
publicHref = rewrittenUrl.href;
|
|
324
|
+
external = true;
|
|
325
|
+
} else publicHref = rewrittenUrl.pathname + rewrittenUrl.search + rewrittenUrl.hash;
|
|
326
|
+
} else {
|
|
327
|
+
href = encodePathLikeUrl(fullPath);
|
|
328
|
+
publicHref = href;
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
publicHref,
|
|
332
|
+
href,
|
|
333
|
+
pathname: nextPathname,
|
|
334
|
+
search: nextSearch,
|
|
335
|
+
searchStr,
|
|
336
|
+
state: nextState,
|
|
337
|
+
hash: hash ?? "",
|
|
338
|
+
external,
|
|
339
|
+
unmaskOnReload: dest.unmaskOnReload
|
|
340
|
+
};
|
|
341
|
+
};
|
|
342
|
+
const buildWithMatches = (dest = {}, maskedDest) => {
|
|
343
|
+
const next = build(dest);
|
|
344
|
+
let maskedNext = maskedDest ? build(maskedDest) : void 0;
|
|
345
|
+
if (!maskedNext) {
|
|
346
|
+
const params = Object.create(null);
|
|
347
|
+
if (this.options.routeMasks) {
|
|
348
|
+
const match = findFlatMatch(next.pathname, this.processedTree);
|
|
349
|
+
if (match) {
|
|
350
|
+
Object.assign(params, match.rawParams);
|
|
351
|
+
const { from: _from, params: maskParams, ...maskProps } = match.route;
|
|
352
|
+
const nextParams = maskParams === false || maskParams === null ? Object.create(null) : (maskParams ?? true) === true ? params : Object.assign(params, functionalUpdate(maskParams, params));
|
|
353
|
+
maskedDest = {
|
|
354
|
+
from: opts.from,
|
|
355
|
+
...maskProps,
|
|
356
|
+
params: nextParams
|
|
357
|
+
};
|
|
358
|
+
maskedNext = build(maskedDest);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (maskedNext) next.maskedLocation = maskedNext;
|
|
363
|
+
return next;
|
|
364
|
+
};
|
|
365
|
+
if (opts.mask) return buildWithMatches(opts, {
|
|
366
|
+
from: opts.from,
|
|
367
|
+
...opts.mask
|
|
368
|
+
});
|
|
369
|
+
return buildWithMatches(opts);
|
|
370
|
+
};
|
|
371
|
+
this.commitLocation = async ({ viewTransition, ignoreBlocker, ...next }) => {
|
|
372
|
+
const isSameState = () => {
|
|
373
|
+
const ignoredProps = [
|
|
374
|
+
"key",
|
|
375
|
+
"__TSR_key",
|
|
376
|
+
"__TSR_index",
|
|
377
|
+
"__hashScrollIntoViewOptions"
|
|
378
|
+
];
|
|
379
|
+
ignoredProps.forEach((prop) => {
|
|
380
|
+
next.state[prop] = this.latestLocation.state[prop];
|
|
381
|
+
});
|
|
382
|
+
const isEqual = deepEqual(next.state, this.latestLocation.state);
|
|
383
|
+
ignoredProps.forEach((prop) => {
|
|
384
|
+
delete next.state[prop];
|
|
385
|
+
});
|
|
386
|
+
return isEqual;
|
|
387
|
+
};
|
|
388
|
+
const isSameUrl = trimPathRight(this.latestLocation.href) === trimPathRight(next.href);
|
|
389
|
+
let previousCommitPromise = this.commitLocationPromise;
|
|
390
|
+
this.commitLocationPromise = createControlledPromise(() => {
|
|
391
|
+
previousCommitPromise?.resolve();
|
|
392
|
+
previousCommitPromise = void 0;
|
|
393
|
+
});
|
|
394
|
+
if (isSameUrl && isSameState()) this.load();
|
|
395
|
+
else {
|
|
396
|
+
let { maskedLocation, hashScrollIntoView, ...nextHistory } = next;
|
|
397
|
+
if (maskedLocation) {
|
|
398
|
+
nextHistory = {
|
|
399
|
+
...maskedLocation,
|
|
400
|
+
state: {
|
|
401
|
+
...maskedLocation.state,
|
|
402
|
+
__tempKey: void 0,
|
|
403
|
+
__tempLocation: {
|
|
404
|
+
...nextHistory,
|
|
405
|
+
search: nextHistory.searchStr,
|
|
406
|
+
state: {
|
|
407
|
+
...nextHistory.state,
|
|
408
|
+
__tempKey: void 0,
|
|
409
|
+
__tempLocation: void 0,
|
|
410
|
+
__TSR_key: void 0,
|
|
411
|
+
key: void 0
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
if (nextHistory.unmaskOnReload ?? this.options.unmaskOnReload ?? false) nextHistory.state.__tempKey = this.tempLocationKey;
|
|
417
|
+
}
|
|
418
|
+
nextHistory.state.__hashScrollIntoViewOptions = hashScrollIntoView ?? this.options.defaultHashScrollIntoView ?? true;
|
|
419
|
+
this.shouldViewTransition = viewTransition;
|
|
420
|
+
this.history[next.replace ? "replace" : "push"](nextHistory.publicHref, nextHistory.state, { ignoreBlocker });
|
|
421
|
+
}
|
|
422
|
+
this.resetNextScroll = next.resetScroll ?? true;
|
|
423
|
+
if (!this.history.subscribers.size) this.load();
|
|
424
|
+
return this.commitLocationPromise;
|
|
425
|
+
};
|
|
426
|
+
this.buildAndCommitLocation = ({ replace, resetScroll, hashScrollIntoView, viewTransition, ignoreBlocker, href, ...rest } = {}) => {
|
|
427
|
+
if (href) {
|
|
428
|
+
const currentIndex = this.history.location.state.__TSR_index;
|
|
429
|
+
const parsed = parseHref(href, { __TSR_index: replace ? currentIndex : currentIndex + 1 });
|
|
430
|
+
const hrefUrl = new URL(parsed.pathname, this.origin);
|
|
431
|
+
rest.to = executeRewriteInput(this.rewrite, hrefUrl).pathname;
|
|
432
|
+
rest.search = this.options.parseSearch(parsed.search);
|
|
433
|
+
rest.hash = parsed.hash.slice(1);
|
|
434
|
+
}
|
|
435
|
+
const location = this.buildLocation({
|
|
436
|
+
...rest,
|
|
437
|
+
_includeValidateSearch: true
|
|
438
|
+
});
|
|
439
|
+
this.pendingBuiltLocation = location;
|
|
440
|
+
const commitPromise = this.commitLocation({
|
|
441
|
+
...location,
|
|
442
|
+
viewTransition,
|
|
443
|
+
replace,
|
|
444
|
+
resetScroll,
|
|
445
|
+
hashScrollIntoView,
|
|
446
|
+
ignoreBlocker
|
|
447
|
+
});
|
|
448
|
+
Promise.resolve().then(() => {
|
|
449
|
+
if (this.pendingBuiltLocation === location) this.pendingBuiltLocation = void 0;
|
|
450
|
+
});
|
|
451
|
+
return commitPromise;
|
|
452
|
+
};
|
|
453
|
+
this.navigate = async ({ to, reloadDocument, href, publicHref, ...rest }) => {
|
|
454
|
+
let hrefIsUrl = false;
|
|
455
|
+
if (href) try {
|
|
456
|
+
new URL(`${href}`);
|
|
457
|
+
hrefIsUrl = true;
|
|
458
|
+
} catch {}
|
|
459
|
+
if (hrefIsUrl && !reloadDocument) reloadDocument = true;
|
|
460
|
+
if (reloadDocument) {
|
|
461
|
+
if (to !== void 0 || !href) {
|
|
462
|
+
const location = this.buildLocation({
|
|
463
|
+
to,
|
|
464
|
+
...rest
|
|
465
|
+
});
|
|
466
|
+
href = href ?? location.publicHref;
|
|
467
|
+
publicHref = publicHref ?? location.publicHref;
|
|
468
|
+
}
|
|
469
|
+
const reloadHref = !hrefIsUrl && publicHref ? publicHref : href;
|
|
470
|
+
if (isDangerousProtocol(reloadHref, this.protocolAllowlist)) {
|
|
471
|
+
if (process.env.NODE_ENV !== "production") console.warn(`Blocked navigation to dangerous protocol: ${reloadHref}`);
|
|
472
|
+
return Promise.resolve();
|
|
473
|
+
}
|
|
474
|
+
if (!rest.ignoreBlocker) {
|
|
475
|
+
const blockers = this.history.getBlockers?.() ?? [];
|
|
476
|
+
for (const blocker of blockers) if (blocker?.blockerFn) {
|
|
477
|
+
if (await blocker.blockerFn({
|
|
478
|
+
currentLocation: this.latestLocation,
|
|
479
|
+
nextLocation: this.latestLocation,
|
|
480
|
+
action: "PUSH"
|
|
481
|
+
})) return Promise.resolve();
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (rest.replace) window.location.replace(reloadHref);
|
|
485
|
+
else window.location.href = reloadHref;
|
|
486
|
+
return Promise.resolve();
|
|
487
|
+
}
|
|
488
|
+
return this.buildAndCommitLocation({
|
|
489
|
+
...rest,
|
|
490
|
+
href,
|
|
491
|
+
to,
|
|
492
|
+
_isNavigate: true
|
|
493
|
+
});
|
|
494
|
+
};
|
|
495
|
+
this.beforeLoad = () => {
|
|
496
|
+
this.cancelMatches();
|
|
497
|
+
this.updateLatestLocation();
|
|
498
|
+
if (isServer ?? this.isServer) {
|
|
499
|
+
const nextLocation = this.buildLocation({
|
|
500
|
+
to: this.latestLocation.pathname,
|
|
501
|
+
search: true,
|
|
502
|
+
params: true,
|
|
503
|
+
hash: true,
|
|
504
|
+
state: true,
|
|
505
|
+
_includeValidateSearch: true
|
|
506
|
+
});
|
|
507
|
+
if (this.latestLocation.publicHref !== nextLocation.publicHref) {
|
|
508
|
+
const href = this.getParsedLocationHref(nextLocation);
|
|
509
|
+
if (nextLocation.external) throw redirect({ href });
|
|
510
|
+
else throw redirect({
|
|
511
|
+
href,
|
|
512
|
+
_builtLocation: nextLocation
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
const pendingMatches = this.matchRoutes(this.latestLocation);
|
|
517
|
+
this.__store.setState((s) => ({
|
|
518
|
+
...s,
|
|
519
|
+
status: "pending",
|
|
520
|
+
statusCode: 200,
|
|
521
|
+
isLoading: true,
|
|
522
|
+
location: this.latestLocation,
|
|
523
|
+
pendingMatches,
|
|
524
|
+
cachedMatches: s.cachedMatches.filter((d) => !pendingMatches.some((e) => e.id === d.id))
|
|
525
|
+
}));
|
|
526
|
+
};
|
|
527
|
+
this.load = async (opts) => {
|
|
528
|
+
let redirect;
|
|
529
|
+
let notFound;
|
|
530
|
+
let loadPromise;
|
|
531
|
+
const previousLocation = this.state.resolvedLocation ?? this.state.location;
|
|
532
|
+
loadPromise = new Promise((resolve) => {
|
|
533
|
+
this.startTransition(async () => {
|
|
534
|
+
try {
|
|
535
|
+
this.beforeLoad();
|
|
536
|
+
const next = this.latestLocation;
|
|
537
|
+
const prevLocation = this.state.resolvedLocation;
|
|
538
|
+
if (!this.state.redirect) this.emit({
|
|
539
|
+
type: "onBeforeNavigate",
|
|
540
|
+
...getLocationChangeInfo({
|
|
541
|
+
resolvedLocation: prevLocation,
|
|
542
|
+
location: next
|
|
543
|
+
})
|
|
544
|
+
});
|
|
545
|
+
this.emit({
|
|
546
|
+
type: "onBeforeLoad",
|
|
547
|
+
...getLocationChangeInfo({
|
|
548
|
+
resolvedLocation: prevLocation,
|
|
549
|
+
location: next
|
|
550
|
+
})
|
|
551
|
+
});
|
|
552
|
+
await loadMatches({
|
|
553
|
+
router: this,
|
|
554
|
+
sync: opts?.sync,
|
|
555
|
+
forceStaleReload: previousLocation.href === next.href,
|
|
556
|
+
matches: this.state.pendingMatches,
|
|
557
|
+
location: next,
|
|
558
|
+
updateMatch: this.updateMatch,
|
|
559
|
+
onReady: async () => {
|
|
560
|
+
this.startTransition(() => {
|
|
561
|
+
this.startViewTransition(async () => {
|
|
562
|
+
let exitingMatches = [];
|
|
563
|
+
let hookExitingMatches = [];
|
|
564
|
+
let hookEnteringMatches = [];
|
|
565
|
+
let hookStayingMatches = [];
|
|
566
|
+
batch$1(() => {
|
|
567
|
+
this.__store.setState((s) => {
|
|
568
|
+
const previousMatches = s.matches;
|
|
569
|
+
const newMatches = s.pendingMatches || s.matches;
|
|
570
|
+
exitingMatches = previousMatches.filter((match) => !newMatches.some((d) => d.id === match.id));
|
|
571
|
+
hookExitingMatches = previousMatches.filter((match) => !newMatches.some((d) => d.routeId === match.routeId));
|
|
572
|
+
hookEnteringMatches = newMatches.filter((match) => !previousMatches.some((d) => d.routeId === match.routeId));
|
|
573
|
+
hookStayingMatches = newMatches.filter((match) => previousMatches.some((d) => d.routeId === match.routeId));
|
|
574
|
+
return {
|
|
575
|
+
...s,
|
|
576
|
+
isLoading: false,
|
|
577
|
+
loadedAt: Date.now(),
|
|
578
|
+
matches: newMatches,
|
|
579
|
+
pendingMatches: void 0,
|
|
580
|
+
cachedMatches: [...s.cachedMatches, ...exitingMatches.filter((d) => d.status !== "error" && d.status !== "notFound" && d.status !== "redirected")]
|
|
581
|
+
};
|
|
582
|
+
});
|
|
583
|
+
this.clearExpiredCache();
|
|
584
|
+
});
|
|
585
|
+
[
|
|
586
|
+
[hookExitingMatches, "onLeave"],
|
|
587
|
+
[hookEnteringMatches, "onEnter"],
|
|
588
|
+
[hookStayingMatches, "onStay"]
|
|
589
|
+
].forEach(([matches, hook]) => {
|
|
590
|
+
matches.forEach((match) => {
|
|
591
|
+
this.looseRoutesById[match.routeId].options[hook]?.(match);
|
|
592
|
+
});
|
|
593
|
+
});
|
|
594
|
+
});
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
} catch (err) {
|
|
599
|
+
if (isRedirect(err)) {
|
|
600
|
+
redirect = err;
|
|
601
|
+
if (!(isServer ?? this.isServer)) this.navigate({
|
|
602
|
+
...redirect.options,
|
|
603
|
+
replace: true,
|
|
604
|
+
ignoreBlocker: true
|
|
605
|
+
});
|
|
606
|
+
} else if (isNotFound(err)) notFound = err;
|
|
607
|
+
this.__store.setState((s) => ({
|
|
608
|
+
...s,
|
|
609
|
+
statusCode: redirect ? redirect.status : notFound ? 404 : s.matches.some((d) => d.status === "error") ? 500 : 200,
|
|
610
|
+
redirect
|
|
611
|
+
}));
|
|
612
|
+
}
|
|
613
|
+
if (this.latestLoadPromise === loadPromise) {
|
|
614
|
+
this.commitLocationPromise?.resolve();
|
|
615
|
+
this.latestLoadPromise = void 0;
|
|
616
|
+
this.commitLocationPromise = void 0;
|
|
617
|
+
}
|
|
618
|
+
resolve();
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
this.latestLoadPromise = loadPromise;
|
|
622
|
+
await loadPromise;
|
|
623
|
+
while (this.latestLoadPromise && loadPromise !== this.latestLoadPromise) await this.latestLoadPromise;
|
|
624
|
+
let newStatusCode = void 0;
|
|
625
|
+
if (this.hasNotFoundMatch()) newStatusCode = 404;
|
|
626
|
+
else if (this.__store.state.matches.some((d) => d.status === "error")) newStatusCode = 500;
|
|
627
|
+
if (newStatusCode !== void 0) this.__store.setState((s) => ({
|
|
628
|
+
...s,
|
|
629
|
+
statusCode: newStatusCode
|
|
630
|
+
}));
|
|
631
|
+
};
|
|
632
|
+
this.startViewTransition = (fn) => {
|
|
633
|
+
const shouldViewTransition = this.shouldViewTransition ?? this.options.defaultViewTransition;
|
|
634
|
+
this.shouldViewTransition = void 0;
|
|
635
|
+
if (shouldViewTransition && typeof document !== "undefined" && "startViewTransition" in document && typeof document.startViewTransition === "function") {
|
|
636
|
+
let startViewTransitionParams;
|
|
637
|
+
if (typeof shouldViewTransition === "object" && this.isViewTransitionTypesSupported) {
|
|
638
|
+
const next = this.latestLocation;
|
|
639
|
+
const prevLocation = this.state.resolvedLocation;
|
|
640
|
+
const resolvedViewTransitionTypes = typeof shouldViewTransition.types === "function" ? shouldViewTransition.types(getLocationChangeInfo({
|
|
641
|
+
resolvedLocation: prevLocation,
|
|
642
|
+
location: next
|
|
643
|
+
})) : shouldViewTransition.types;
|
|
644
|
+
if (resolvedViewTransitionTypes === false) {
|
|
645
|
+
fn();
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
startViewTransitionParams = {
|
|
649
|
+
update: fn,
|
|
650
|
+
types: resolvedViewTransitionTypes
|
|
651
|
+
};
|
|
652
|
+
} else startViewTransitionParams = fn;
|
|
653
|
+
document.startViewTransition(startViewTransitionParams);
|
|
654
|
+
} else fn();
|
|
655
|
+
};
|
|
656
|
+
this.updateMatch = (id, updater) => {
|
|
657
|
+
this.startTransition(() => {
|
|
658
|
+
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" : "";
|
|
659
|
+
if (matchesKey) if (matchesKey === "cachedMatches") this.__store.setState((s) => ({
|
|
660
|
+
...s,
|
|
661
|
+
cachedMatches: filterRedirectedCachedMatches(s.cachedMatches.map((d) => d.id === id ? updater(d) : d))
|
|
662
|
+
}));
|
|
663
|
+
else this.__store.setState((s) => ({
|
|
664
|
+
...s,
|
|
665
|
+
[matchesKey]: s[matchesKey]?.map((d) => d.id === id ? updater(d) : d)
|
|
666
|
+
}));
|
|
667
|
+
});
|
|
668
|
+
};
|
|
669
|
+
this.getMatch = (matchId) => {
|
|
670
|
+
const findFn = (d) => d.id === matchId;
|
|
671
|
+
return this.state.cachedMatches.find(findFn) ?? this.state.pendingMatches?.find(findFn) ?? this.state.matches.find(findFn);
|
|
672
|
+
};
|
|
673
|
+
this.invalidate = (opts) => {
|
|
674
|
+
const invalidate = (d) => {
|
|
675
|
+
if (opts?.filter?.(d) ?? true) return {
|
|
676
|
+
...d,
|
|
677
|
+
invalid: true,
|
|
678
|
+
...opts?.forcePending || d.status === "error" || d.status === "notFound" ? {
|
|
679
|
+
status: "pending",
|
|
680
|
+
error: void 0
|
|
681
|
+
} : void 0
|
|
682
|
+
};
|
|
683
|
+
return d;
|
|
684
|
+
};
|
|
685
|
+
this.__store.setState((s) => ({
|
|
686
|
+
...s,
|
|
687
|
+
matches: s.matches.map(invalidate),
|
|
688
|
+
cachedMatches: s.cachedMatches.map(invalidate),
|
|
689
|
+
pendingMatches: s.pendingMatches?.map(invalidate)
|
|
690
|
+
}));
|
|
691
|
+
this.shouldViewTransition = false;
|
|
692
|
+
return this.load({ sync: opts?.sync });
|
|
693
|
+
};
|
|
694
|
+
this.getParsedLocationHref = (location) => {
|
|
695
|
+
return location.publicHref || "/";
|
|
696
|
+
};
|
|
697
|
+
this.resolveRedirect = (redirect) => {
|
|
698
|
+
const locationHeader = redirect.headers.get("Location");
|
|
699
|
+
if (!redirect.options.href || redirect.options._builtLocation) {
|
|
700
|
+
const location = redirect.options._builtLocation ?? this.buildLocation(redirect.options);
|
|
701
|
+
const href = this.getParsedLocationHref(location);
|
|
702
|
+
redirect.options.href = href;
|
|
703
|
+
redirect.headers.set("Location", href);
|
|
704
|
+
} else if (locationHeader) try {
|
|
705
|
+
const url = new URL(locationHeader);
|
|
706
|
+
if (this.origin && url.origin === this.origin) {
|
|
707
|
+
const href = url.pathname + url.search + url.hash;
|
|
708
|
+
redirect.options.href = href;
|
|
709
|
+
redirect.headers.set("Location", href);
|
|
710
|
+
}
|
|
711
|
+
} catch {}
|
|
712
|
+
if (redirect.options.href && !redirect.options._builtLocation && isDangerousProtocol(redirect.options.href, this.protocolAllowlist)) throw new Error(process.env.NODE_ENV !== "production" ? `Redirect blocked: unsafe protocol in href "${redirect.options.href}". Allowed protocols: ${Array.from(this.protocolAllowlist).join(", ")}.` : "Redirect blocked: unsafe protocol");
|
|
713
|
+
if (!redirect.headers.get("Location")) redirect.headers.set("Location", redirect.options.href);
|
|
714
|
+
return redirect;
|
|
715
|
+
};
|
|
716
|
+
this.clearCache = (opts) => {
|
|
717
|
+
const filter = opts?.filter;
|
|
718
|
+
if (filter !== void 0) this.__store.setState((s) => {
|
|
719
|
+
return {
|
|
720
|
+
...s,
|
|
721
|
+
cachedMatches: s.cachedMatches.filter((m) => !filter(m))
|
|
722
|
+
};
|
|
723
|
+
});
|
|
724
|
+
else this.__store.setState((s) => {
|
|
725
|
+
return {
|
|
726
|
+
...s,
|
|
727
|
+
cachedMatches: []
|
|
728
|
+
};
|
|
729
|
+
});
|
|
730
|
+
};
|
|
731
|
+
this.clearExpiredCache = () => {
|
|
732
|
+
const filter = (d) => {
|
|
733
|
+
const route = this.looseRoutesById[d.routeId];
|
|
734
|
+
if (!route.options.loader) return true;
|
|
735
|
+
const gcTime = (d.preload ? route.options.preloadGcTime ?? this.options.defaultPreloadGcTime : route.options.gcTime ?? this.options.defaultGcTime) ?? 300 * 1e3;
|
|
736
|
+
if (d.status === "error") return true;
|
|
737
|
+
return Date.now() - d.updatedAt >= gcTime;
|
|
738
|
+
};
|
|
739
|
+
this.clearCache({ filter });
|
|
740
|
+
};
|
|
741
|
+
this.loadRouteChunk = loadRouteChunk;
|
|
742
|
+
this.preloadRoute = async (opts) => {
|
|
743
|
+
const next = opts._builtLocation ?? this.buildLocation(opts);
|
|
744
|
+
let matches = this.matchRoutes(next, {
|
|
745
|
+
throwOnError: true,
|
|
746
|
+
preload: true,
|
|
747
|
+
dest: opts
|
|
748
|
+
});
|
|
749
|
+
const activeMatchIds = new Set([...this.state.matches, ...this.state.pendingMatches ?? []].map((d) => d.id));
|
|
750
|
+
const loadedMatchIds = new Set([...activeMatchIds, ...this.state.cachedMatches.map((d) => d.id)]);
|
|
751
|
+
batch$1(() => {
|
|
752
|
+
matches.forEach((match) => {
|
|
753
|
+
if (!loadedMatchIds.has(match.id)) this.__store.setState((s) => ({
|
|
754
|
+
...s,
|
|
755
|
+
cachedMatches: [...s.cachedMatches, match]
|
|
756
|
+
}));
|
|
757
|
+
});
|
|
758
|
+
});
|
|
759
|
+
try {
|
|
760
|
+
matches = await loadMatches({
|
|
761
|
+
router: this,
|
|
762
|
+
matches,
|
|
763
|
+
location: next,
|
|
764
|
+
preload: true,
|
|
765
|
+
updateMatch: (id, updater) => {
|
|
766
|
+
if (activeMatchIds.has(id)) matches = matches.map((d) => d.id === id ? updater(d) : d);
|
|
767
|
+
else this.updateMatch(id, updater);
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
return matches;
|
|
771
|
+
} catch (err) {
|
|
772
|
+
if (isRedirect(err)) {
|
|
773
|
+
if (err.options.reloadDocument) return;
|
|
774
|
+
return await this.preloadRoute({
|
|
775
|
+
...err.options,
|
|
776
|
+
_fromLocation: next
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
if (!isNotFound(err)) console.error(err);
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
this.matchRoute = (location, opts) => {
|
|
784
|
+
const matchLocation = {
|
|
785
|
+
...location,
|
|
786
|
+
to: location.to ? this.resolvePathWithBase(location.from || "", location.to) : void 0,
|
|
787
|
+
params: location.params || {},
|
|
788
|
+
leaveParams: true
|
|
789
|
+
};
|
|
790
|
+
const next = this.buildLocation(matchLocation);
|
|
791
|
+
if (opts?.pending && this.state.status !== "pending") return false;
|
|
792
|
+
const baseLocation = (opts?.pending === void 0 ? !this.state.isLoading : opts.pending) ? this.latestLocation : this.state.resolvedLocation || this.state.location;
|
|
793
|
+
const match = findSingleMatch(next.pathname, opts?.caseSensitive ?? false, opts?.fuzzy ?? false, baseLocation.pathname, this.processedTree);
|
|
794
|
+
if (!match) return false;
|
|
795
|
+
if (location.params) {
|
|
796
|
+
if (!deepEqual(match.rawParams, location.params, { partial: true })) return false;
|
|
797
|
+
}
|
|
798
|
+
if (opts?.includeSearch ?? true) return deepEqual(baseLocation.search, next.search, { partial: true }) ? match.rawParams : false;
|
|
799
|
+
return match.rawParams;
|
|
800
|
+
};
|
|
801
|
+
this.hasNotFoundMatch = () => {
|
|
802
|
+
return this.__store.state.matches.some((d) => d.status === "notFound" || d.globalNotFound);
|
|
803
|
+
};
|
|
804
|
+
this.update({
|
|
805
|
+
defaultPreloadDelay: 50,
|
|
806
|
+
defaultPendingMs: 1e3,
|
|
807
|
+
defaultPendingMinMs: 500,
|
|
808
|
+
context: void 0,
|
|
809
|
+
...options,
|
|
810
|
+
caseSensitive: options.caseSensitive ?? false,
|
|
811
|
+
notFoundMode: options.notFoundMode ?? "fuzzy",
|
|
812
|
+
stringifySearch: options.stringifySearch ?? defaultStringifySearch,
|
|
813
|
+
parseSearch: options.parseSearch ?? defaultParseSearch,
|
|
814
|
+
protocolAllowlist: options.protocolAllowlist ?? DEFAULT_PROTOCOL_ALLOWLIST
|
|
815
|
+
});
|
|
816
|
+
if (typeof document !== "undefined") self.__TSR_ROUTER__ = this;
|
|
817
|
+
}
|
|
818
|
+
isShell() {
|
|
819
|
+
return !!this.options.isShell;
|
|
820
|
+
}
|
|
821
|
+
isPrerendering() {
|
|
822
|
+
return !!this.options.isPrerendering;
|
|
823
|
+
}
|
|
824
|
+
get state() {
|
|
825
|
+
return this.__store.state;
|
|
826
|
+
}
|
|
827
|
+
setRoutes({ routesById, routesByPath, processedTree }) {
|
|
828
|
+
this.routesById = routesById;
|
|
829
|
+
this.routesByPath = routesByPath;
|
|
830
|
+
this.processedTree = processedTree;
|
|
831
|
+
const notFoundRoute = this.options.notFoundRoute;
|
|
832
|
+
if (notFoundRoute) {
|
|
833
|
+
notFoundRoute.init({ originalIndex: 99999999999 });
|
|
834
|
+
this.routesById[notFoundRoute.id] = notFoundRoute;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
get looseRoutesById() {
|
|
838
|
+
return this.routesById;
|
|
839
|
+
}
|
|
840
|
+
getParentContext(parentMatch) {
|
|
841
|
+
return !parentMatch?.id ? this.options.context ?? void 0 : parentMatch.context ?? this.options.context ?? void 0;
|
|
842
|
+
}
|
|
843
|
+
matchRoutesInternal(next, opts) {
|
|
844
|
+
const matchedRoutesResult = this.getMatchedRoutes(next.pathname);
|
|
845
|
+
const { foundRoute, routeParams, parsedParams } = matchedRoutesResult;
|
|
846
|
+
let { matchedRoutes } = matchedRoutesResult;
|
|
847
|
+
let isGlobalNotFound = false;
|
|
848
|
+
if (foundRoute ? foundRoute.path !== "/" && routeParams["**"] : trimPathRight(next.pathname)) if (this.options.notFoundRoute) matchedRoutes = [...matchedRoutes, this.options.notFoundRoute];
|
|
849
|
+
else isGlobalNotFound = true;
|
|
850
|
+
const globalNotFoundRouteId = isGlobalNotFound ? findGlobalNotFoundRouteId(this.options.notFoundMode, matchedRoutes) : void 0;
|
|
851
|
+
const matches = new Array(matchedRoutes.length);
|
|
852
|
+
const previousMatchesByRouteId = new Map(this.state.matches.map((match) => [match.routeId, match]));
|
|
853
|
+
for (let index = 0; index < matchedRoutes.length; index++) {
|
|
854
|
+
const route = matchedRoutes[index];
|
|
855
|
+
const parentMatch = matches[index - 1];
|
|
856
|
+
let preMatchSearch;
|
|
857
|
+
let strictMatchSearch;
|
|
858
|
+
let searchError;
|
|
859
|
+
{
|
|
860
|
+
const parentSearch = parentMatch?.search ?? next.search;
|
|
861
|
+
const parentStrictSearch = parentMatch?._strictSearch ?? void 0;
|
|
862
|
+
try {
|
|
863
|
+
const strictSearch = validateSearch(route.options.validateSearch, { ...parentSearch }) ?? void 0;
|
|
864
|
+
preMatchSearch = {
|
|
865
|
+
...parentSearch,
|
|
866
|
+
...strictSearch
|
|
867
|
+
};
|
|
868
|
+
strictMatchSearch = {
|
|
869
|
+
...parentStrictSearch,
|
|
870
|
+
...strictSearch
|
|
871
|
+
};
|
|
872
|
+
searchError = void 0;
|
|
873
|
+
} catch (err) {
|
|
874
|
+
let searchParamError = err;
|
|
875
|
+
if (!(err instanceof SearchParamError)) searchParamError = new SearchParamError(err.message, { cause: err });
|
|
876
|
+
if (opts?.throwOnError) throw searchParamError;
|
|
877
|
+
preMatchSearch = parentSearch;
|
|
878
|
+
strictMatchSearch = {};
|
|
879
|
+
searchError = searchParamError;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
const loaderDeps = route.options.loaderDeps?.({ search: preMatchSearch }) ?? "";
|
|
883
|
+
const loaderDepsHash = loaderDeps ? JSON.stringify(loaderDeps) : "";
|
|
884
|
+
const { interpolatedPath, usedParams } = interpolatePath({
|
|
885
|
+
path: route.fullPath,
|
|
886
|
+
params: routeParams,
|
|
887
|
+
decoder: this.pathParamsDecoder,
|
|
888
|
+
server: this.isServer
|
|
889
|
+
});
|
|
890
|
+
const matchId = route.id + interpolatedPath + loaderDepsHash;
|
|
891
|
+
const existingMatch = this.getMatch(matchId);
|
|
892
|
+
const previousMatch = previousMatchesByRouteId.get(route.id);
|
|
893
|
+
const strictParams = existingMatch?._strictParams ?? usedParams;
|
|
894
|
+
let paramsError = void 0;
|
|
895
|
+
if (!existingMatch) try {
|
|
896
|
+
extractStrictParams(route, usedParams, parsedParams, strictParams);
|
|
897
|
+
} catch (err) {
|
|
898
|
+
if (isNotFound(err) || isRedirect(err)) paramsError = err;
|
|
899
|
+
else paramsError = new PathParamError(err.message, { cause: err });
|
|
900
|
+
if (opts?.throwOnError) throw paramsError;
|
|
901
|
+
}
|
|
902
|
+
Object.assign(routeParams, strictParams);
|
|
903
|
+
const cause = previousMatch ? "stay" : "enter";
|
|
904
|
+
let match;
|
|
905
|
+
if (existingMatch) match = {
|
|
906
|
+
...existingMatch,
|
|
907
|
+
cause,
|
|
908
|
+
params: previousMatch?.params ?? routeParams,
|
|
909
|
+
_strictParams: strictParams,
|
|
910
|
+
search: previousMatch ? nullReplaceEqualDeep(previousMatch.search, preMatchSearch) : nullReplaceEqualDeep(existingMatch.search, preMatchSearch),
|
|
911
|
+
_strictSearch: strictMatchSearch
|
|
912
|
+
};
|
|
913
|
+
else {
|
|
914
|
+
const status = route.options.loader || route.options.beforeLoad || route.lazyFn || routeNeedsPreload(route) ? "pending" : "success";
|
|
915
|
+
match = {
|
|
916
|
+
id: matchId,
|
|
917
|
+
ssr: isServer ?? this.isServer ? void 0 : route.options.ssr,
|
|
918
|
+
index,
|
|
919
|
+
routeId: route.id,
|
|
920
|
+
params: previousMatch?.params ?? routeParams,
|
|
921
|
+
_strictParams: strictParams,
|
|
922
|
+
pathname: interpolatedPath,
|
|
923
|
+
updatedAt: Date.now(),
|
|
924
|
+
search: previousMatch ? nullReplaceEqualDeep(previousMatch.search, preMatchSearch) : preMatchSearch,
|
|
925
|
+
_strictSearch: strictMatchSearch,
|
|
926
|
+
searchError: void 0,
|
|
927
|
+
status,
|
|
928
|
+
isFetching: false,
|
|
929
|
+
error: void 0,
|
|
930
|
+
paramsError,
|
|
931
|
+
__routeContext: void 0,
|
|
932
|
+
_nonReactive: { loadPromise: createControlledPromise() },
|
|
933
|
+
__beforeLoadContext: void 0,
|
|
934
|
+
context: {},
|
|
935
|
+
abortController: new AbortController(),
|
|
936
|
+
fetchCount: 0,
|
|
937
|
+
cause,
|
|
938
|
+
loaderDeps: previousMatch ? replaceEqualDeep(previousMatch.loaderDeps, loaderDeps) : loaderDeps,
|
|
939
|
+
invalid: false,
|
|
940
|
+
preload: false,
|
|
941
|
+
links: void 0,
|
|
942
|
+
scripts: void 0,
|
|
943
|
+
headScripts: void 0,
|
|
944
|
+
meta: void 0,
|
|
945
|
+
staticData: route.options.staticData || {},
|
|
946
|
+
fullPath: route.fullPath
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
if (!opts?.preload) match.globalNotFound = globalNotFoundRouteId === route.id;
|
|
950
|
+
match.searchError = searchError;
|
|
951
|
+
const parentContext = this.getParentContext(parentMatch);
|
|
952
|
+
match.context = {
|
|
953
|
+
...parentContext,
|
|
954
|
+
...match.__routeContext,
|
|
955
|
+
...match.__beforeLoadContext
|
|
956
|
+
};
|
|
957
|
+
matches[index] = match;
|
|
958
|
+
}
|
|
959
|
+
for (let index = 0; index < matches.length; index++) {
|
|
960
|
+
const match = matches[index];
|
|
961
|
+
const route = this.looseRoutesById[match.routeId];
|
|
962
|
+
const existingMatch = this.getMatch(match.id);
|
|
963
|
+
const previousMatch = previousMatchesByRouteId.get(match.routeId);
|
|
964
|
+
match.params = previousMatch ? nullReplaceEqualDeep(previousMatch.params, routeParams) : routeParams;
|
|
965
|
+
if (!existingMatch) {
|
|
966
|
+
const parentMatch = matches[index - 1];
|
|
967
|
+
const parentContext = this.getParentContext(parentMatch);
|
|
968
|
+
if (route.options.context) {
|
|
969
|
+
const contextFnContext = {
|
|
970
|
+
deps: match.loaderDeps,
|
|
971
|
+
params: match.params,
|
|
972
|
+
context: parentContext ?? {},
|
|
973
|
+
location: next,
|
|
974
|
+
navigate: (opts) => this.navigate({
|
|
975
|
+
...opts,
|
|
976
|
+
_fromLocation: next
|
|
977
|
+
}),
|
|
978
|
+
buildLocation: this.buildLocation,
|
|
979
|
+
cause: match.cause,
|
|
980
|
+
abortController: match.abortController,
|
|
981
|
+
preload: !!match.preload,
|
|
982
|
+
matches,
|
|
983
|
+
routeId: route.id
|
|
984
|
+
};
|
|
985
|
+
match.__routeContext = route.options.context(contextFnContext) ?? void 0;
|
|
986
|
+
}
|
|
987
|
+
match.context = {
|
|
988
|
+
...parentContext,
|
|
989
|
+
...match.__routeContext,
|
|
990
|
+
...match.__beforeLoadContext
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
return matches;
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* Lightweight route matching for buildLocation.
|
|
998
|
+
* Only computes fullPath, accumulated search, and params - skipping expensive
|
|
999
|
+
* operations like AbortController, ControlledPromise, loaderDeps, and full match objects.
|
|
1000
|
+
*/
|
|
1001
|
+
matchRoutesLightweight(location) {
|
|
1002
|
+
const { matchedRoutes, routeParams, parsedParams } = this.getMatchedRoutes(location.pathname);
|
|
1003
|
+
const lastRoute = last(matchedRoutes);
|
|
1004
|
+
const accumulatedSearch = { ...location.search };
|
|
1005
|
+
for (const route of matchedRoutes) try {
|
|
1006
|
+
Object.assign(accumulatedSearch, validateSearch(route.options.validateSearch, accumulatedSearch));
|
|
1007
|
+
} catch {}
|
|
1008
|
+
const lastStateMatch = last(this.state.matches);
|
|
1009
|
+
const canReuseParams = lastStateMatch && lastStateMatch.routeId === lastRoute.id && location.pathname === this.state.location.pathname;
|
|
1010
|
+
let params;
|
|
1011
|
+
if (canReuseParams) params = lastStateMatch.params;
|
|
1012
|
+
else {
|
|
1013
|
+
const strictParams = Object.assign(Object.create(null), routeParams);
|
|
1014
|
+
for (const route of matchedRoutes) try {
|
|
1015
|
+
extractStrictParams(route, routeParams, parsedParams ?? {}, strictParams);
|
|
1016
|
+
} catch {}
|
|
1017
|
+
params = strictParams;
|
|
1018
|
+
}
|
|
1019
|
+
return {
|
|
1020
|
+
matchedRoutes,
|
|
1021
|
+
fullPath: lastRoute.fullPath,
|
|
1022
|
+
search: accumulatedSearch,
|
|
1023
|
+
params
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
/** Error thrown when search parameter validation fails. */
|
|
1028
|
+
var SearchParamError = class extends Error {};
|
|
1029
|
+
/** Error thrown when path parameter parsing/validation fails. */
|
|
1030
|
+
var PathParamError = class extends Error {};
|
|
1031
|
+
var normalize = (str) => str.endsWith("/") && str.length > 1 ? str.slice(0, -1) : str;
|
|
1375
1032
|
function comparePaths(a, b) {
|
|
1376
|
-
|
|
1033
|
+
return normalize(a) === normalize(b);
|
|
1377
1034
|
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Lazily import a module function and forward arguments to it, retaining
|
|
1037
|
+
* parameter and return types for the selected export key.
|
|
1038
|
+
*/
|
|
1378
1039
|
function lazyFn(fn, key) {
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
};
|
|
1040
|
+
return async (...args) => {
|
|
1041
|
+
return (await fn())[key || "default"](...args);
|
|
1042
|
+
};
|
|
1383
1043
|
}
|
|
1044
|
+
/** Create an initial RouterState from a parsed location. */
|
|
1384
1045
|
function getInitialRouterState(location) {
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1046
|
+
return {
|
|
1047
|
+
loadedAt: 0,
|
|
1048
|
+
isLoading: false,
|
|
1049
|
+
isTransitioning: false,
|
|
1050
|
+
status: "idle",
|
|
1051
|
+
resolvedLocation: void 0,
|
|
1052
|
+
location,
|
|
1053
|
+
matches: [],
|
|
1054
|
+
pendingMatches: [],
|
|
1055
|
+
cachedMatches: [],
|
|
1056
|
+
statusCode: 200
|
|
1057
|
+
};
|
|
1397
1058
|
}
|
|
1398
|
-
function validateSearch(
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
}
|
|
1410
|
-
if ("parse" in validateSearch2) {
|
|
1411
|
-
return validateSearch2.parse(input);
|
|
1412
|
-
}
|
|
1413
|
-
if (typeof validateSearch2 === "function") {
|
|
1414
|
-
return validateSearch2(input);
|
|
1415
|
-
}
|
|
1416
|
-
return {};
|
|
1059
|
+
function validateSearch(validateSearch, input) {
|
|
1060
|
+
if (validateSearch == null) return {};
|
|
1061
|
+
if ("~standard" in validateSearch) {
|
|
1062
|
+
const result = validateSearch["~standard"].validate(input);
|
|
1063
|
+
if (result instanceof Promise) throw new SearchParamError("Async validation not supported");
|
|
1064
|
+
if (result.issues) throw new SearchParamError(JSON.stringify(result.issues, void 0, 2), { cause: result });
|
|
1065
|
+
return result.value;
|
|
1066
|
+
}
|
|
1067
|
+
if ("parse" in validateSearch) return validateSearch.parse(input);
|
|
1068
|
+
if (typeof validateSearch === "function") return validateSearch(input);
|
|
1069
|
+
return {};
|
|
1417
1070
|
}
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
}) {
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1071
|
+
/**
|
|
1072
|
+
* Build the matched route chain and extract params for a pathname.
|
|
1073
|
+
* Falls back to the root route if no specific route is found.
|
|
1074
|
+
*/
|
|
1075
|
+
function getMatchedRoutes({ pathname, routesById, processedTree }) {
|
|
1076
|
+
const routeParams = Object.create(null);
|
|
1077
|
+
const trimmedPath = trimPathRight(pathname);
|
|
1078
|
+
let foundRoute = void 0;
|
|
1079
|
+
let parsedParams = void 0;
|
|
1080
|
+
const match = findRouteMatch(trimmedPath, processedTree, true);
|
|
1081
|
+
if (match) {
|
|
1082
|
+
foundRoute = match.route;
|
|
1083
|
+
Object.assign(routeParams, match.rawParams);
|
|
1084
|
+
parsedParams = Object.assign(Object.create(null), match.parsedParams);
|
|
1085
|
+
}
|
|
1086
|
+
return {
|
|
1087
|
+
matchedRoutes: match?.branch || [routesById["__root__"]],
|
|
1088
|
+
routeParams,
|
|
1089
|
+
foundRoute,
|
|
1090
|
+
parsedParams
|
|
1091
|
+
};
|
|
1435
1092
|
}
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
const middleware = buildMiddlewareChain(destRoutes);
|
|
1443
|
-
return middleware(search, dest, _includeValidateSearch ?? false);
|
|
1093
|
+
/**
|
|
1094
|
+
* TODO: once caches are persisted across requests on the server,
|
|
1095
|
+
* we can cache the built middleware chain using `last(destRoutes)` as the key
|
|
1096
|
+
*/
|
|
1097
|
+
function applySearchMiddleware({ search, dest, destRoutes, _includeValidateSearch }) {
|
|
1098
|
+
return buildMiddlewareChain(destRoutes)(search, dest, _includeValidateSearch ?? false);
|
|
1444
1099
|
}
|
|
1445
1100
|
function buildMiddlewareChain(destRoutes) {
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
context.middlewares.push(final);
|
|
1504
|
-
const applyNext = (index, currentSearch, middlewares) => {
|
|
1505
|
-
if (index >= middlewares.length) {
|
|
1506
|
-
return currentSearch;
|
|
1507
|
-
}
|
|
1508
|
-
const middleware = middlewares[index];
|
|
1509
|
-
const next = (newSearch) => {
|
|
1510
|
-
return applyNext(index + 1, newSearch, middlewares);
|
|
1511
|
-
};
|
|
1512
|
-
return middleware({ search: currentSearch, next });
|
|
1513
|
-
};
|
|
1514
|
-
return function middleware(search, dest, _includeValidateSearch) {
|
|
1515
|
-
context.dest = dest;
|
|
1516
|
-
context._includeValidateSearch = _includeValidateSearch;
|
|
1517
|
-
return applyNext(0, search, context.middlewares);
|
|
1518
|
-
};
|
|
1101
|
+
const context = {
|
|
1102
|
+
dest: null,
|
|
1103
|
+
_includeValidateSearch: false,
|
|
1104
|
+
middlewares: []
|
|
1105
|
+
};
|
|
1106
|
+
for (const route of destRoutes) {
|
|
1107
|
+
if ("search" in route.options) {
|
|
1108
|
+
if (route.options.search?.middlewares) context.middlewares.push(...route.options.search.middlewares);
|
|
1109
|
+
} else if (route.options.preSearchFilters || route.options.postSearchFilters) {
|
|
1110
|
+
const legacyMiddleware = ({ search, next }) => {
|
|
1111
|
+
let nextSearch = search;
|
|
1112
|
+
if ("preSearchFilters" in route.options && route.options.preSearchFilters) nextSearch = route.options.preSearchFilters.reduce((prev, next) => next(prev), search);
|
|
1113
|
+
const result = next(nextSearch);
|
|
1114
|
+
if ("postSearchFilters" in route.options && route.options.postSearchFilters) return route.options.postSearchFilters.reduce((prev, next) => next(prev), result);
|
|
1115
|
+
return result;
|
|
1116
|
+
};
|
|
1117
|
+
context.middlewares.push(legacyMiddleware);
|
|
1118
|
+
}
|
|
1119
|
+
if (route.options.validateSearch) {
|
|
1120
|
+
const validate = ({ search, next }) => {
|
|
1121
|
+
const result = next(search);
|
|
1122
|
+
if (!context._includeValidateSearch) return result;
|
|
1123
|
+
try {
|
|
1124
|
+
return {
|
|
1125
|
+
...result,
|
|
1126
|
+
...validateSearch(route.options.validateSearch, result) ?? void 0
|
|
1127
|
+
};
|
|
1128
|
+
} catch {
|
|
1129
|
+
return result;
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
1132
|
+
context.middlewares.push(validate);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
const final = ({ search }) => {
|
|
1136
|
+
const dest = context.dest;
|
|
1137
|
+
if (!dest.search) return {};
|
|
1138
|
+
if (dest.search === true) return search;
|
|
1139
|
+
return functionalUpdate(dest.search, search);
|
|
1140
|
+
};
|
|
1141
|
+
context.middlewares.push(final);
|
|
1142
|
+
const applyNext = (index, currentSearch, middlewares) => {
|
|
1143
|
+
if (index >= middlewares.length) return currentSearch;
|
|
1144
|
+
const middleware = middlewares[index];
|
|
1145
|
+
const next = (newSearch) => {
|
|
1146
|
+
return applyNext(index + 1, newSearch, middlewares);
|
|
1147
|
+
};
|
|
1148
|
+
return middleware({
|
|
1149
|
+
search: currentSearch,
|
|
1150
|
+
next
|
|
1151
|
+
});
|
|
1152
|
+
};
|
|
1153
|
+
return function middleware(search, dest, _includeValidateSearch) {
|
|
1154
|
+
context.dest = dest;
|
|
1155
|
+
context._includeValidateSearch = _includeValidateSearch;
|
|
1156
|
+
return applyNext(0, search, context.middlewares);
|
|
1157
|
+
};
|
|
1519
1158
|
}
|
|
1520
1159
|
function findGlobalNotFoundRouteId(notFoundMode, routes) {
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
}
|
|
1529
|
-
return rootRouteId;
|
|
1160
|
+
if (notFoundMode !== "root") for (let i = routes.length - 1; i >= 0; i--) {
|
|
1161
|
+
const route = routes[i];
|
|
1162
|
+
if (route.children) return route.id;
|
|
1163
|
+
}
|
|
1164
|
+
return rootRouteId;
|
|
1530
1165
|
}
|
|
1531
1166
|
function extractStrictParams(route, referenceParams, parsedParams, accumulatedParams) {
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
}
|
|
1540
|
-
} else {
|
|
1541
|
-
const result = parseParams(accumulatedParams);
|
|
1542
|
-
Object.assign(accumulatedParams, result);
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1167
|
+
const parseParams = route.options.params?.parse ?? route.options.parseParams;
|
|
1168
|
+
if (parseParams) if (route.options.skipRouteOnParseError) {
|
|
1169
|
+
for (const key in referenceParams) if (key in parsedParams) accumulatedParams[key] = parsedParams[key];
|
|
1170
|
+
} else {
|
|
1171
|
+
const result = parseParams(accumulatedParams);
|
|
1172
|
+
Object.assign(accumulatedParams, result);
|
|
1173
|
+
}
|
|
1545
1174
|
}
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
defaultSerializeError,
|
|
1551
|
-
getInitialRouterState,
|
|
1552
|
-
getLocationChangeInfo,
|
|
1553
|
-
getMatchedRoutes,
|
|
1554
|
-
lazyFn,
|
|
1555
|
-
trailingSlashOptions
|
|
1556
|
-
};
|
|
1557
|
-
//# sourceMappingURL=router.js.map
|
|
1175
|
+
//#endregion
|
|
1176
|
+
export { PathParamError, RouterCore, SearchParamError, defaultSerializeError, getInitialRouterState, getLocationChangeInfo, getMatchedRoutes, lazyFn, trailingSlashOptions };
|
|
1177
|
+
|
|
1178
|
+
//# sourceMappingURL=router.js.map
|