@tanstack/router-core 1.120.4-alpha.19 → 1.120.4
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/fileRoute.d.cts +2 -6
- package/dist/cjs/index.cjs +0 -3
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +6 -6
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +1 -18
- package/dist/cjs/path.cjs +16 -130
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/path.d.cts +0 -17
- package/dist/cjs/redirect.cjs +14 -17
- package/dist/cjs/redirect.cjs.map +1 -1
- package/dist/cjs/redirect.d.cts +7 -13
- package/dist/cjs/route.cjs +1 -12
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +14 -15
- package/dist/cjs/router.cjs +155 -231
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +3 -46
- package/dist/cjs/scroll-restoration.cjs +23 -12
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.d.cts +1 -1
- package/dist/cjs/typePrimitives.d.cts +2 -2
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +0 -2
- package/dist/esm/fileRoute.d.ts +2 -6
- package/dist/esm/index.d.ts +6 -6
- package/dist/esm/index.js +2 -5
- package/dist/esm/link.d.ts +1 -18
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/path.d.ts +0 -17
- package/dist/esm/path.js +16 -130
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/redirect.d.ts +7 -13
- package/dist/esm/redirect.js +14 -17
- package/dist/esm/redirect.js.map +1 -1
- package/dist/esm/route.d.ts +14 -15
- package/dist/esm/route.js +1 -12
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +3 -46
- package/dist/esm/router.js +158 -234
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/scroll-restoration.d.ts +1 -1
- package/dist/esm/scroll-restoration.js +23 -12
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/typePrimitives.d.ts +2 -2
- package/dist/esm/utils.d.ts +0 -2
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/fileRoute.ts +1 -90
- package/src/index.ts +6 -14
- package/src/link.ts +11 -97
- package/src/path.ts +16 -181
- package/src/redirect.ts +22 -37
- package/src/route.ts +35 -104
- package/src/router.ts +209 -332
- package/src/scroll-restoration.ts +44 -27
- package/src/typePrimitives.ts +2 -2
- package/src/utils.ts +0 -14
package/src/path.ts
CHANGED
|
@@ -5,9 +5,6 @@ import type { AnyPathParams } from './route'
|
|
|
5
5
|
export interface Segment {
|
|
6
6
|
type: 'pathname' | 'param' | 'wildcard'
|
|
7
7
|
value: string
|
|
8
|
-
// Add a new property to store the static segment if present
|
|
9
|
-
prefixSegment?: string
|
|
10
|
-
suffixSegment?: string
|
|
11
8
|
}
|
|
12
9
|
|
|
13
10
|
export function joinPaths(paths: Array<string | undefined>) {
|
|
@@ -140,52 +137,10 @@ export function resolvePath({
|
|
|
140
137
|
}
|
|
141
138
|
}
|
|
142
139
|
|
|
143
|
-
const
|
|
144
|
-
if (segment.type === 'param') {
|
|
145
|
-
const param = segment.value.substring(1)
|
|
146
|
-
if (segment.prefixSegment && segment.suffixSegment) {
|
|
147
|
-
return `${segment.prefixSegment}{$${param}}${segment.suffixSegment}`
|
|
148
|
-
} else if (segment.prefixSegment) {
|
|
149
|
-
return `${segment.prefixSegment}{$${param}}`
|
|
150
|
-
} else if (segment.suffixSegment) {
|
|
151
|
-
return `{$${param}}${segment.suffixSegment}`
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (segment.type === 'wildcard') {
|
|
155
|
-
if (segment.prefixSegment && segment.suffixSegment) {
|
|
156
|
-
return `${segment.prefixSegment}{$}${segment.suffixSegment}`
|
|
157
|
-
} else if (segment.prefixSegment) {
|
|
158
|
-
return `${segment.prefixSegment}{$}`
|
|
159
|
-
} else if (segment.suffixSegment) {
|
|
160
|
-
return `{$}${segment.suffixSegment}`
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return segment.value
|
|
164
|
-
})
|
|
165
|
-
const joined = joinPaths([basepath, ...segmentValues])
|
|
140
|
+
const joined = joinPaths([basepath, ...baseSegments.map((d) => d.value)])
|
|
166
141
|
return cleanPath(joined)
|
|
167
142
|
}
|
|
168
143
|
|
|
169
|
-
const PARAM_RE = /^\$.{1,}$/ // $paramName
|
|
170
|
-
const PARAM_W_CURLY_BRACES_RE = /^(.*?)\{(\$[a-zA-Z_$][a-zA-Z0-9_$]*)\}(.*)$/ // prefix{$paramName}suffix
|
|
171
|
-
const WILDCARD_RE = /^\$$/ // $
|
|
172
|
-
const WILDCARD_W_CURLY_BRACES_RE = /^(.*?)\{\$\}(.*)$/ // prefix{$}suffix
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Required: `/foo/$bar` ✅
|
|
176
|
-
* Prefix and Suffix: `/foo/prefix${bar}suffix` ✅
|
|
177
|
-
* Wildcard: `/foo/$` ✅
|
|
178
|
-
* Wildcard with Prefix and Suffix: `/foo/prefix{$}suffix` ✅
|
|
179
|
-
*
|
|
180
|
-
* Future:
|
|
181
|
-
* Optional: `/foo/{-bar}`
|
|
182
|
-
* Optional named segment: `/foo/{bar}`
|
|
183
|
-
* Optional named segment with Prefix and Suffix: `/foo/prefix{-bar}suffix`
|
|
184
|
-
* Escape special characters:
|
|
185
|
-
* - `/foo/[$]` - Static route
|
|
186
|
-
* - `/foo/[$]{$foo} - Dynamic route with a static prefix of `$`
|
|
187
|
-
* - `/foo/{$foo}[$]` - Dynamic route with a static suffix of `$`
|
|
188
|
-
*/
|
|
189
144
|
export function parsePathname(pathname?: string): Array<Segment> {
|
|
190
145
|
if (!pathname) {
|
|
191
146
|
return []
|
|
@@ -212,55 +167,20 @@ export function parsePathname(pathname?: string): Array<Segment> {
|
|
|
212
167
|
|
|
213
168
|
segments.push(
|
|
214
169
|
...split.map((part): Segment => {
|
|
215
|
-
|
|
216
|
-
const wildcardBracesMatch = part.match(WILDCARD_W_CURLY_BRACES_RE)
|
|
217
|
-
if (wildcardBracesMatch) {
|
|
218
|
-
const prefix = wildcardBracesMatch[1]
|
|
219
|
-
const suffix = wildcardBracesMatch[2]
|
|
170
|
+
if (part === '$' || part === '*') {
|
|
220
171
|
return {
|
|
221
172
|
type: 'wildcard',
|
|
222
|
-
value:
|
|
223
|
-
prefixSegment: prefix || undefined,
|
|
224
|
-
suffixSegment: suffix || undefined,
|
|
173
|
+
value: part,
|
|
225
174
|
}
|
|
226
175
|
}
|
|
227
176
|
|
|
228
|
-
|
|
229
|
-
const paramBracesMatch = part.match(PARAM_W_CURLY_BRACES_RE)
|
|
230
|
-
if (paramBracesMatch) {
|
|
231
|
-
const prefix = paramBracesMatch[1]
|
|
232
|
-
const paramName = paramBracesMatch[2]
|
|
233
|
-
const suffix = paramBracesMatch[3]
|
|
177
|
+
if (part.charAt(0) === '$') {
|
|
234
178
|
return {
|
|
235
179
|
type: 'param',
|
|
236
|
-
value:
|
|
237
|
-
prefixSegment: prefix || undefined,
|
|
238
|
-
suffixSegment: suffix || undefined,
|
|
180
|
+
value: part,
|
|
239
181
|
}
|
|
240
182
|
}
|
|
241
183
|
|
|
242
|
-
// Check for bare parameter format: $paramName (without curly braces)
|
|
243
|
-
if (PARAM_RE.test(part)) {
|
|
244
|
-
const paramName = part.substring(1)
|
|
245
|
-
return {
|
|
246
|
-
type: 'param',
|
|
247
|
-
value: '$' + paramName,
|
|
248
|
-
prefixSegment: undefined,
|
|
249
|
-
suffixSegment: undefined,
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Check for bare wildcard: $ (without curly braces)
|
|
254
|
-
if (WILDCARD_RE.test(part)) {
|
|
255
|
-
return {
|
|
256
|
-
type: 'wildcard',
|
|
257
|
-
value: '$',
|
|
258
|
-
prefixSegment: undefined,
|
|
259
|
-
suffixSegment: undefined,
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// Handle regular pathname segment
|
|
264
184
|
return {
|
|
265
185
|
type: 'pathname',
|
|
266
186
|
value: part.includes('%25')
|
|
@@ -328,13 +248,9 @@ export function interpolatePath({
|
|
|
328
248
|
interpolatedPathSegments.map((segment) => {
|
|
329
249
|
if (segment.type === 'wildcard') {
|
|
330
250
|
usedParams._splat = params._splat
|
|
331
|
-
const segmentPrefix = segment.prefixSegment || ''
|
|
332
|
-
const segmentSuffix = segment.suffixSegment || ''
|
|
333
251
|
const value = encodeParam('_splat')
|
|
334
|
-
if (leaveWildcards) {
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
return `${segmentPrefix}${value}${segmentSuffix}`
|
|
252
|
+
if (leaveWildcards) return `${segment.value}${value ?? ''}`
|
|
253
|
+
return value
|
|
338
254
|
}
|
|
339
255
|
|
|
340
256
|
if (segment.type === 'param') {
|
|
@@ -343,14 +259,11 @@ export function interpolatePath({
|
|
|
343
259
|
isMissingParams = true
|
|
344
260
|
}
|
|
345
261
|
usedParams[key] = params[key]
|
|
346
|
-
|
|
347
|
-
const segmentPrefix = segment.prefixSegment || ''
|
|
348
|
-
const segmentSuffix = segment.suffixSegment || ''
|
|
349
262
|
if (leaveParams) {
|
|
350
263
|
const value = encodeParam(segment.value)
|
|
351
|
-
return `${
|
|
264
|
+
return `${segment.value}${value ?? ''}`
|
|
352
265
|
}
|
|
353
|
-
return
|
|
266
|
+
return encodeParam(key) ?? 'undefined'
|
|
354
267
|
}
|
|
355
268
|
|
|
356
269
|
return segment.value
|
|
@@ -477,57 +390,9 @@ export function matchByPath(
|
|
|
477
390
|
|
|
478
391
|
if (routeSegment) {
|
|
479
392
|
if (routeSegment.type === 'wildcard') {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
let _splat: string
|
|
484
|
-
|
|
485
|
-
// If this is a wildcard with prefix/suffix, we need to handle the first segment specially
|
|
486
|
-
if (routeSegment.prefixSegment || routeSegment.suffixSegment) {
|
|
487
|
-
if (!baseSegment) return false
|
|
488
|
-
|
|
489
|
-
const prefix = routeSegment.prefixSegment || ''
|
|
490
|
-
const suffix = routeSegment.suffixSegment || ''
|
|
491
|
-
|
|
492
|
-
// Check if the base segment starts with prefix and ends with suffix
|
|
493
|
-
const baseValue = baseSegment.value
|
|
494
|
-
if ('prefixSegment' in routeSegment) {
|
|
495
|
-
if (!baseValue.startsWith(prefix)) {
|
|
496
|
-
return false
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
if ('suffixSegment' in routeSegment) {
|
|
500
|
-
if (
|
|
501
|
-
!baseSegments[baseSegments.length - 1]?.value.endsWith(suffix)
|
|
502
|
-
) {
|
|
503
|
-
return false
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
let rejoinedSplat = decodeURI(
|
|
508
|
-
joinPaths(remainingBaseSegments.map((d) => d.value)),
|
|
509
|
-
)
|
|
510
|
-
|
|
511
|
-
// Remove the prefix and suffix from the rejoined splat
|
|
512
|
-
if (prefix && rejoinedSplat.startsWith(prefix)) {
|
|
513
|
-
rejoinedSplat = rejoinedSplat.slice(prefix.length)
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
if (suffix && rejoinedSplat.endsWith(suffix)) {
|
|
517
|
-
rejoinedSplat = rejoinedSplat.slice(
|
|
518
|
-
0,
|
|
519
|
-
rejoinedSplat.length - suffix.length,
|
|
520
|
-
)
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
_splat = rejoinedSplat
|
|
524
|
-
} else {
|
|
525
|
-
// If no prefix/suffix, just rejoin the remaining segments
|
|
526
|
-
_splat = decodeURI(
|
|
527
|
-
joinPaths(remainingBaseSegments.map((d) => d.value)),
|
|
528
|
-
)
|
|
529
|
-
}
|
|
530
|
-
|
|
393
|
+
const _splat = decodeURI(
|
|
394
|
+
joinPaths(baseSegments.slice(i).map((d) => d.value)),
|
|
395
|
+
)
|
|
531
396
|
// TODO: Deprecate *
|
|
532
397
|
params['*'] = _splat
|
|
533
398
|
params['_splat'] = _splat
|
|
@@ -561,41 +426,11 @@ export function matchByPath(
|
|
|
561
426
|
if (baseSegment.value === '/') {
|
|
562
427
|
return false
|
|
563
428
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
if (routeSegment.prefixSegment || routeSegment.suffixSegment) {
|
|
569
|
-
const prefix = routeSegment.prefixSegment || ''
|
|
570
|
-
const suffix = routeSegment.suffixSegment || ''
|
|
571
|
-
|
|
572
|
-
// Check if the base segment starts with prefix and ends with suffix
|
|
573
|
-
const baseValue = baseSegment.value
|
|
574
|
-
if (prefix && !baseValue.startsWith(prefix)) {
|
|
575
|
-
return false
|
|
576
|
-
}
|
|
577
|
-
if (suffix && !baseValue.endsWith(suffix)) {
|
|
578
|
-
return false
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
let paramValue = baseValue
|
|
582
|
-
if (prefix && paramValue.startsWith(prefix)) {
|
|
583
|
-
paramValue = paramValue.slice(prefix.length)
|
|
584
|
-
}
|
|
585
|
-
if (suffix && paramValue.endsWith(suffix)) {
|
|
586
|
-
paramValue = paramValue.slice(
|
|
587
|
-
0,
|
|
588
|
-
paramValue.length - suffix.length,
|
|
589
|
-
)
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
_paramValue = decodeURIComponent(paramValue)
|
|
593
|
-
} else {
|
|
594
|
-
// If no prefix/suffix, just decode the base segment value
|
|
595
|
-
_paramValue = decodeURIComponent(baseSegment.value)
|
|
429
|
+
if (baseSegment.value.charAt(0) !== '$') {
|
|
430
|
+
params[routeSegment.value.substring(1)] = decodeURIComponent(
|
|
431
|
+
baseSegment.value,
|
|
432
|
+
)
|
|
596
433
|
}
|
|
597
|
-
|
|
598
|
-
params[routeSegment.value.substring(1)] = _paramValue
|
|
599
434
|
}
|
|
600
435
|
}
|
|
601
436
|
|
package/src/redirect.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { NavigateOptions } from './link'
|
|
2
2
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
3
|
+
import type { PickAsRequired } from './utils'
|
|
3
4
|
|
|
4
5
|
export type AnyRedirect = Redirect<any, any, any, any, any>
|
|
5
6
|
|
|
@@ -12,17 +13,6 @@ export type Redirect<
|
|
|
12
13
|
TTo extends string | undefined = undefined,
|
|
13
14
|
TMaskFrom extends string = TFrom,
|
|
14
15
|
TMaskTo extends string = '.',
|
|
15
|
-
> = Response & {
|
|
16
|
-
options: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>
|
|
17
|
-
redirectHandled?: boolean
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type RedirectOptions<
|
|
21
|
-
TRouter extends AnyRouter = RegisteredRouter,
|
|
22
|
-
TFrom extends string = string,
|
|
23
|
-
TTo extends string | undefined = undefined,
|
|
24
|
-
TMaskFrom extends string = TFrom,
|
|
25
|
-
TMaskTo extends string = '.',
|
|
26
16
|
> = {
|
|
27
17
|
href?: string
|
|
28
18
|
/**
|
|
@@ -52,7 +42,12 @@ export type ResolvedRedirect<
|
|
|
52
42
|
TTo extends string = '',
|
|
53
43
|
TMaskFrom extends string = TFrom,
|
|
54
44
|
TMaskTo extends string = '',
|
|
55
|
-
> =
|
|
45
|
+
> = PickAsRequired<
|
|
46
|
+
Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,
|
|
47
|
+
'code' | 'statusCode' | 'headers'
|
|
48
|
+
> & {
|
|
49
|
+
href: string
|
|
50
|
+
}
|
|
56
51
|
|
|
57
52
|
export function redirect<
|
|
58
53
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
@@ -61,40 +56,30 @@ export function redirect<
|
|
|
61
56
|
const TMaskFrom extends string = TFrom,
|
|
62
57
|
const TMaskTo extends string = '',
|
|
63
58
|
>(
|
|
64
|
-
opts:
|
|
59
|
+
opts: Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,
|
|
65
60
|
): Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> {
|
|
61
|
+
;(opts as any).isRedirect = true
|
|
66
62
|
opts.statusCode = opts.statusCode || opts.code || 307
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
opts
|
|
63
|
+
opts.headers = opts.headers || {}
|
|
64
|
+
if (!opts.reloadDocument) {
|
|
65
|
+
opts.reloadDocument = false
|
|
66
|
+
try {
|
|
67
|
+
new URL(`${opts.href}`)
|
|
68
|
+
opts.reloadDocument = true
|
|
69
|
+
} catch {}
|
|
70
|
+
}
|
|
76
71
|
|
|
77
72
|
if (opts.throw) {
|
|
78
|
-
throw
|
|
73
|
+
throw opts
|
|
79
74
|
}
|
|
80
75
|
|
|
81
|
-
return
|
|
76
|
+
return opts
|
|
82
77
|
}
|
|
83
78
|
|
|
84
79
|
export function isRedirect(obj: any): obj is AnyRedirect {
|
|
85
|
-
return
|
|
80
|
+
return !!obj?.isRedirect
|
|
86
81
|
}
|
|
87
82
|
|
|
88
|
-
export function isResolvedRedirect(
|
|
89
|
-
obj
|
|
90
|
-
): obj is AnyRedirect & { options: { href: string } } {
|
|
91
|
-
return isRedirect(obj) && !!obj.options.href
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function parseRedirect(obj: any) {
|
|
95
|
-
if (typeof obj === 'object' && obj.isSerializedRedirect) {
|
|
96
|
-
return redirect(obj)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return undefined
|
|
83
|
+
export function isResolvedRedirect(obj: any): obj is ResolvedRedirect {
|
|
84
|
+
return !!obj?.isRedirect && obj.href
|
|
100
85
|
}
|
package/src/route.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import invariant from 'tiny-invariant'
|
|
2
1
|
import { joinPaths, trimPathLeft } from './path'
|
|
3
2
|
import { notFound } from './not-found'
|
|
4
3
|
import { rootRouteId } from './root'
|
|
@@ -21,8 +20,6 @@ import type {
|
|
|
21
20
|
Constrain,
|
|
22
21
|
Expand,
|
|
23
22
|
IntersectAssign,
|
|
24
|
-
LooseAsyncReturnType,
|
|
25
|
-
LooseReturnType,
|
|
26
23
|
NoInfer,
|
|
27
24
|
} from './utils'
|
|
28
25
|
import type {
|
|
@@ -153,24 +150,27 @@ export type ResolveSearchSchema<TSearchValidator> =
|
|
|
153
150
|
? ResolveSearchSchemaFn<TSearchValidator['parse']>
|
|
154
151
|
: ResolveSearchSchemaFn<TSearchValidator>
|
|
155
152
|
|
|
156
|
-
export type
|
|
157
|
-
|
|
158
|
-
}
|
|
153
|
+
export type ParseSplatParams<TPath extends string> = TPath &
|
|
154
|
+
`${string}$` extends never
|
|
155
|
+
? TPath & `${string}$/${string}` extends never
|
|
156
|
+
? never
|
|
157
|
+
: '_splat'
|
|
158
|
+
: '_splat'
|
|
159
159
|
|
|
160
|
-
export
|
|
161
|
-
|
|
160
|
+
export interface SplatParams {
|
|
161
|
+
_splat?: string
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
export type ResolveParams<
|
|
165
|
-
TPath extends
|
|
166
|
-
|
|
167
|
-
|
|
164
|
+
export type ResolveParams<TPath extends string> =
|
|
165
|
+
ParseSplatParams<TPath> extends never
|
|
166
|
+
? Record<ParsePathParams<TPath>, string>
|
|
167
|
+
: Record<ParsePathParams<TPath>, string> & SplatParams
|
|
168
168
|
|
|
169
169
|
export type ParseParamsFn<in out TPath extends string, in out TParams> = (
|
|
170
|
-
rawParams:
|
|
171
|
-
) => TParams extends
|
|
170
|
+
rawParams: ResolveParams<TPath>,
|
|
171
|
+
) => TParams extends Record<ParsePathParams<TPath>, any>
|
|
172
172
|
? TParams
|
|
173
|
-
:
|
|
173
|
+
: Record<ParsePathParams<TPath>, any>
|
|
174
174
|
|
|
175
175
|
export type StringifyParamsFn<in out TPath extends string, in out TParams> = (
|
|
176
176
|
params: TParams,
|
|
@@ -270,6 +270,20 @@ export type TrimPathRight<T extends string> = T extends '/'
|
|
|
270
270
|
? TrimPathRight<U>
|
|
271
271
|
: T
|
|
272
272
|
|
|
273
|
+
export type LooseReturnType<T> = T extends (
|
|
274
|
+
...args: Array<any>
|
|
275
|
+
) => infer TReturn
|
|
276
|
+
? TReturn
|
|
277
|
+
: never
|
|
278
|
+
|
|
279
|
+
export type LooseAsyncReturnType<T> = T extends (
|
|
280
|
+
...args: Array<any>
|
|
281
|
+
) => infer TReturn
|
|
282
|
+
? TReturn extends Promise<infer TReturn>
|
|
283
|
+
? TReturn
|
|
284
|
+
: TReturn
|
|
285
|
+
: never
|
|
286
|
+
|
|
273
287
|
export type ContextReturnType<TContextFn> = unknown extends TContextFn
|
|
274
288
|
? TContextFn
|
|
275
289
|
: LooseReturnType<TContextFn> extends never
|
|
@@ -434,7 +448,7 @@ export interface RouteExtensions<in out TId, in out TFullPath> {
|
|
|
434
448
|
}
|
|
435
449
|
|
|
436
450
|
export type RouteLazyFn<TRoute extends AnyRoute> = (
|
|
437
|
-
lazyFn: () => Promise<LazyRoute
|
|
451
|
+
lazyFn: () => Promise<LazyRoute>,
|
|
438
452
|
) => TRoute
|
|
439
453
|
|
|
440
454
|
export type RouteAddChildrenFn<
|
|
@@ -588,26 +602,7 @@ export interface Route<
|
|
|
588
602
|
>
|
|
589
603
|
isRoot: TParentRoute extends AnyRoute ? true : false
|
|
590
604
|
_componentsPromise?: Promise<Array<void>>
|
|
591
|
-
lazyFn?: () => Promise<
|
|
592
|
-
LazyRoute<
|
|
593
|
-
Route<
|
|
594
|
-
TParentRoute,
|
|
595
|
-
TPath,
|
|
596
|
-
TFullPath,
|
|
597
|
-
TCustomId,
|
|
598
|
-
TId,
|
|
599
|
-
TSearchValidator,
|
|
600
|
-
TParams,
|
|
601
|
-
TRouterContext,
|
|
602
|
-
TRouteContextFn,
|
|
603
|
-
TBeforeLoadFn,
|
|
604
|
-
TLoaderDeps,
|
|
605
|
-
TLoaderFn,
|
|
606
|
-
TChildren,
|
|
607
|
-
TFileRouteTypes
|
|
608
|
-
>
|
|
609
|
-
>
|
|
610
|
-
>
|
|
605
|
+
lazyFn?: () => Promise<LazyRoute>
|
|
611
606
|
_lazyPromise?: Promise<void>
|
|
612
607
|
rank: number
|
|
613
608
|
to: TrimPathRight<TFullPath>
|
|
@@ -626,24 +621,7 @@ export interface Route<
|
|
|
626
621
|
TBeforeLoadFn
|
|
627
622
|
>,
|
|
628
623
|
) => this
|
|
629
|
-
lazy: RouteLazyFn<
|
|
630
|
-
Route<
|
|
631
|
-
TParentRoute,
|
|
632
|
-
TPath,
|
|
633
|
-
TFullPath,
|
|
634
|
-
TCustomId,
|
|
635
|
-
TId,
|
|
636
|
-
TSearchValidator,
|
|
637
|
-
TParams,
|
|
638
|
-
TRouterContext,
|
|
639
|
-
TRouteContextFn,
|
|
640
|
-
TBeforeLoadFn,
|
|
641
|
-
TLoaderDeps,
|
|
642
|
-
TLoaderFn,
|
|
643
|
-
TChildren,
|
|
644
|
-
TFileRouteTypes
|
|
645
|
-
>
|
|
646
|
-
>
|
|
624
|
+
lazy: RouteLazyFn<this>
|
|
647
625
|
addChildren: RouteAddChildrenFn<
|
|
648
626
|
TParentRoute,
|
|
649
627
|
TPath,
|
|
@@ -1358,26 +1336,7 @@ export class BaseRoute<
|
|
|
1358
1336
|
children?: TChildren
|
|
1359
1337
|
originalIndex?: number
|
|
1360
1338
|
rank!: number
|
|
1361
|
-
lazyFn?: () => Promise<
|
|
1362
|
-
LazyRoute<
|
|
1363
|
-
Route<
|
|
1364
|
-
TParentRoute,
|
|
1365
|
-
TPath,
|
|
1366
|
-
TFullPath,
|
|
1367
|
-
TCustomId,
|
|
1368
|
-
TId,
|
|
1369
|
-
TSearchValidator,
|
|
1370
|
-
TParams,
|
|
1371
|
-
TRouterContext,
|
|
1372
|
-
TRouteContextFn,
|
|
1373
|
-
TBeforeLoadFn,
|
|
1374
|
-
TLoaderDeps,
|
|
1375
|
-
TLoaderFn,
|
|
1376
|
-
TChildren,
|
|
1377
|
-
TFileRouteTypes
|
|
1378
|
-
>
|
|
1379
|
-
>
|
|
1380
|
-
>
|
|
1339
|
+
lazyFn?: () => Promise<LazyRoute>
|
|
1381
1340
|
_lazyPromise?: Promise<void>
|
|
1382
1341
|
_componentsPromise?: Promise<Array<void>>
|
|
1383
1342
|
|
|
@@ -1450,8 +1409,7 @@ export class BaseRoute<
|
|
|
1450
1409
|
if (isRoot) {
|
|
1451
1410
|
this._path = rootRouteId as TPath
|
|
1452
1411
|
} else if (!this.parentRoute) {
|
|
1453
|
-
|
|
1454
|
-
false,
|
|
1412
|
+
throw new Error(
|
|
1455
1413
|
`Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,
|
|
1456
1414
|
)
|
|
1457
1415
|
}
|
|
@@ -1491,16 +1449,6 @@ export class BaseRoute<
|
|
|
1491
1449
|
this._ssr = options?.ssr ?? opts.defaultSsr ?? true
|
|
1492
1450
|
}
|
|
1493
1451
|
|
|
1494
|
-
clone = (other: typeof this) => {
|
|
1495
|
-
this._path = other._path
|
|
1496
|
-
this._id = other._id
|
|
1497
|
-
this._fullPath = other._fullPath
|
|
1498
|
-
this._to = other._to
|
|
1499
|
-
this._ssr = other._ssr
|
|
1500
|
-
this.options.getParentRoute = other.options.getParentRoute
|
|
1501
|
-
this.children = other.children
|
|
1502
|
-
}
|
|
1503
|
-
|
|
1504
1452
|
addChildren: RouteAddChildrenFn<
|
|
1505
1453
|
TParentRoute,
|
|
1506
1454
|
TPath,
|
|
@@ -1614,24 +1562,7 @@ export class BaseRoute<
|
|
|
1614
1562
|
return this
|
|
1615
1563
|
}
|
|
1616
1564
|
|
|
1617
|
-
lazy: RouteLazyFn<
|
|
1618
|
-
Route<
|
|
1619
|
-
TParentRoute,
|
|
1620
|
-
TPath,
|
|
1621
|
-
TFullPath,
|
|
1622
|
-
TCustomId,
|
|
1623
|
-
TId,
|
|
1624
|
-
TSearchValidator,
|
|
1625
|
-
TParams,
|
|
1626
|
-
TRouterContext,
|
|
1627
|
-
TRouteContextFn,
|
|
1628
|
-
TBeforeLoadFn,
|
|
1629
|
-
TLoaderDeps,
|
|
1630
|
-
TLoaderFn,
|
|
1631
|
-
TChildren,
|
|
1632
|
-
TFileRouteTypes
|
|
1633
|
-
>
|
|
1634
|
-
> = (lazyFn) => {
|
|
1565
|
+
lazy: RouteLazyFn<this> = (lazyFn) => {
|
|
1635
1566
|
this.lazyFn = lazyFn
|
|
1636
1567
|
return this
|
|
1637
1568
|
}
|