@tanstack/react-router 1.1.9 → 1.1.11
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/build/cjs/fileRoute.js.map +1 -1
- package/build/cjs/link.js.map +1 -1
- package/build/cjs/route.js.map +1 -1
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +351 -351
- package/build/types/fileRoute.d.ts +5 -4
- package/build/types/link.d.ts +4 -4
- package/build/types/route.d.ts +27 -22
- package/build/types/routeInfo.d.ts +1 -1
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/fileRoute.ts +21 -3
- package/src/link.tsx +9 -8
- package/src/route.ts +68 -42
- package/src/routeInfo.ts +1 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.11",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@tanstack/store": "^0.1.3",
|
|
45
45
|
"tiny-invariant": "^1.3.1",
|
|
46
46
|
"tiny-warning": "^1.0.3",
|
|
47
|
-
"@tanstack/history": "1.1.
|
|
47
|
+
"@tanstack/history": "1.1.11"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "rollup --config rollup.config.js"
|
package/src/fileRoute.ts
CHANGED
|
@@ -56,12 +56,20 @@ export type RemoveUnderScores<T extends string> = Replace<
|
|
|
56
56
|
'/'
|
|
57
57
|
>
|
|
58
58
|
|
|
59
|
+
type ReplaceFirstOccurrence<
|
|
60
|
+
T extends string,
|
|
61
|
+
Search extends string,
|
|
62
|
+
Replacement extends string,
|
|
63
|
+
> = T extends `${infer Prefix}${Search}${infer Suffix}`
|
|
64
|
+
? `${Prefix}${Replacement}${Suffix}`
|
|
65
|
+
: T
|
|
66
|
+
|
|
59
67
|
export type ResolveFilePath<
|
|
60
68
|
TParentRoute extends AnyRoute,
|
|
61
69
|
TFilePath extends string,
|
|
62
70
|
> = TParentRoute['id'] extends RootRouteId
|
|
63
71
|
? TrimPathLeft<TFilePath>
|
|
64
|
-
:
|
|
72
|
+
: ReplaceFirstOccurrence<
|
|
65
73
|
TrimPathLeft<TFilePath>,
|
|
66
74
|
TrimPathLeft<TParentRoute['types']['customId']>,
|
|
67
75
|
''
|
|
@@ -72,7 +80,9 @@ export type FileRoutePath<
|
|
|
72
80
|
TFilePath extends string,
|
|
73
81
|
> = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}`
|
|
74
82
|
? string
|
|
75
|
-
: ResolveFilePath<TParentRoute, TFilePath>
|
|
83
|
+
: ResolveFilePath<TParentRoute, TFilePath> extends `/_${infer _}`
|
|
84
|
+
? string
|
|
85
|
+
: ResolveFilePath<TParentRoute, TFilePath>
|
|
76
86
|
|
|
77
87
|
export class FileRoute<
|
|
78
88
|
TFilePath extends keyof FileRoutesByPath,
|
|
@@ -115,7 +125,13 @@ export class FileRoute<
|
|
|
115
125
|
TParentRoute['types']['allParams'],
|
|
116
126
|
TParams
|
|
117
127
|
>,
|
|
118
|
-
|
|
128
|
+
TRouteContextReturn extends
|
|
129
|
+
RouteConstraints['TRouteContext'] = RouteContext,
|
|
130
|
+
TRouteContext extends RouteConstraints['TRouteContext'] = [
|
|
131
|
+
TRouteContextReturn,
|
|
132
|
+
] extends [never]
|
|
133
|
+
? RouteContext
|
|
134
|
+
: TRouteContextReturn,
|
|
119
135
|
TContext extends Expand<
|
|
120
136
|
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
121
137
|
> = Expand<
|
|
@@ -139,6 +155,7 @@ export class FileRoute<
|
|
|
139
155
|
TFullSearchSchema,
|
|
140
156
|
TParams,
|
|
141
157
|
TAllParams,
|
|
158
|
+
TRouteContextReturn,
|
|
142
159
|
TRouteContext,
|
|
143
160
|
TContext,
|
|
144
161
|
TLoaderDeps,
|
|
@@ -160,6 +177,7 @@ export class FileRoute<
|
|
|
160
177
|
TFullSearchSchema,
|
|
161
178
|
TParams,
|
|
162
179
|
TAllParams,
|
|
180
|
+
TRouteContextReturn,
|
|
163
181
|
TRouteContext,
|
|
164
182
|
TContext,
|
|
165
183
|
TRouterContext,
|
package/src/link.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import * as React from 'react'
|
|
|
2
2
|
import { useMatch } from './Matches'
|
|
3
3
|
import { useRouter, useRouterState } from './RouterProvider'
|
|
4
4
|
import { Trim } from './fileRoute'
|
|
5
|
-
import { AnyRoute, ReactNode } from './route'
|
|
5
|
+
import { AnyRoute, ReactNode, RootSearchSchema } from './route'
|
|
6
6
|
import {
|
|
7
7
|
AllParams,
|
|
8
8
|
FullSearchSchema,
|
|
@@ -171,7 +171,7 @@ type ParamVariant = 'PATH' | 'SEARCH'
|
|
|
171
171
|
export type ParamOptions<
|
|
172
172
|
TRouteTree extends AnyRoute,
|
|
173
173
|
TFrom,
|
|
174
|
-
TTo,
|
|
174
|
+
TTo extends string,
|
|
175
175
|
TResolved,
|
|
176
176
|
TParamVariant extends ParamVariant,
|
|
177
177
|
TFromRouteType extends
|
|
@@ -184,12 +184,13 @@ export type ParamOptions<
|
|
|
184
184
|
| 'fullSearchSchemaInput' = TParamVariant extends 'PATH'
|
|
185
185
|
? 'allParams'
|
|
186
186
|
: 'fullSearchSchemaInput',
|
|
187
|
-
TFromParams = Expand<RouteByPath<TRouteTree, TFrom>['types'][TFromRouteType]
|
|
188
|
-
|
|
187
|
+
TFromParams = Expand<Exclude<RouteByPath<TRouteTree, TFrom>['types'][TFromRouteType], RootSearchSchema>>,
|
|
188
|
+
TToIndex = RouteByPath<TRouteTree, `${TTo}/`> extends never ? TTo : `${TTo}/`,
|
|
189
|
+
TToParams = TToIndex extends ''
|
|
189
190
|
? TFromParams
|
|
190
191
|
: never extends TResolved
|
|
191
|
-
? Expand<RouteByPath<TRouteTree,
|
|
192
|
-
: Expand<RouteByPath<TRouteTree, TResolved>['types'][TToRouteType]
|
|
192
|
+
? Expand<Exclude<RouteByPath<TRouteTree, TToIndex>['types'][TToRouteType], RootSearchSchema>>
|
|
193
|
+
: Expand<Exclude<RouteByPath<TRouteTree, TResolved>['types'][TToRouteType], RootSearchSchema>>,
|
|
193
194
|
TReducer = ParamsReducer<TFromParams, TToParams>,
|
|
194
195
|
> = Expand<WithoutEmpty<PickRequired<TToParams>>> extends never
|
|
195
196
|
? Partial<MakeParamOption<TParamVariant, true | TReducer>>
|
|
@@ -209,14 +210,14 @@ type MakePathParamOptions<T> = { params: T }
|
|
|
209
210
|
export type SearchParamOptions<
|
|
210
211
|
TRouteTree extends AnyRoute,
|
|
211
212
|
TFrom,
|
|
212
|
-
TTo,
|
|
213
|
+
TTo extends string,
|
|
213
214
|
TResolved,
|
|
214
215
|
> = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'SEARCH'>
|
|
215
216
|
|
|
216
217
|
export type PathParamOptions<
|
|
217
218
|
TRouteTree extends AnyRoute,
|
|
218
219
|
TFrom,
|
|
219
|
-
TTo,
|
|
220
|
+
TTo extends string,
|
|
220
221
|
TResolved,
|
|
221
222
|
> = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'PATH'>
|
|
222
223
|
|
package/src/route.ts
CHANGED
|
@@ -67,6 +67,7 @@ export type RouteOptions<
|
|
|
67
67
|
TFullSearchSchema extends Record<string, any> = TSearchSchema,
|
|
68
68
|
TParams extends AnyPathParams = AnyPathParams,
|
|
69
69
|
TAllParams extends AnyPathParams = TParams,
|
|
70
|
+
TRouteContextReturn extends RouteContext = RouteContext,
|
|
70
71
|
TRouteContext extends RouteContext = RouteContext,
|
|
71
72
|
TAllContext extends Record<string, any> = AnyContext,
|
|
72
73
|
TLoaderDeps extends Record<string, any> = {},
|
|
@@ -82,6 +83,7 @@ export type RouteOptions<
|
|
|
82
83
|
TFullSearchSchema,
|
|
83
84
|
TParams,
|
|
84
85
|
TAllParams,
|
|
86
|
+
TRouteContextReturn,
|
|
85
87
|
TRouteContext,
|
|
86
88
|
TAllContext,
|
|
87
89
|
TLoaderDeps,
|
|
@@ -105,6 +107,7 @@ export type BaseRouteOptions<
|
|
|
105
107
|
TFullSearchSchema extends Record<string, any> = TSearchSchema,
|
|
106
108
|
TParams extends AnyPathParams = {},
|
|
107
109
|
TAllParams = ParamsFallback<TPath, TParams>,
|
|
110
|
+
TRouteContextReturn extends RouteContext = RouteContext,
|
|
108
111
|
TRouteContext extends RouteContext = RouteContext,
|
|
109
112
|
TAllContext extends Record<string, any> = AnyContext,
|
|
110
113
|
TLoaderDeps extends Record<string, any> = {},
|
|
@@ -122,36 +125,27 @@ export type BaseRouteOptions<
|
|
|
122
125
|
TRouteContext
|
|
123
126
|
>,
|
|
124
127
|
) => any)
|
|
125
|
-
} &
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
loaderDeps?: (opts: { search: TFullSearchSchema }) => TLoaderDeps
|
|
147
|
-
loader?: RouteLoaderFn<
|
|
148
|
-
TAllParams,
|
|
149
|
-
NoInfer<TLoaderDeps>,
|
|
150
|
-
NoInfer<TAllContext>,
|
|
151
|
-
NoInfer<TRouteContext>,
|
|
152
|
-
TLoaderData
|
|
153
|
-
>
|
|
154
|
-
} & (
|
|
128
|
+
} & {
|
|
129
|
+
// This async function is called before a route is loaded.
|
|
130
|
+
// If an error is thrown here, the route's loader will not be called.
|
|
131
|
+
// If thrown during a navigation, the navigation will be cancelled and the error will be passed to the `onError` function.
|
|
132
|
+
// If thrown during a preload event, the error will be logged to the console.
|
|
133
|
+
beforeLoad?: BeforeLoadFn<
|
|
134
|
+
TFullSearchSchema,
|
|
135
|
+
TParentRoute,
|
|
136
|
+
TAllParams,
|
|
137
|
+
TRouteContextReturn
|
|
138
|
+
>
|
|
139
|
+
} & {
|
|
140
|
+
loaderDeps?: (opts: { search: TFullSearchSchema }) => TLoaderDeps
|
|
141
|
+
loader?: RouteLoaderFn<
|
|
142
|
+
TAllParams,
|
|
143
|
+
NoInfer<TLoaderDeps>,
|
|
144
|
+
NoInfer<TAllContext>,
|
|
145
|
+
NoInfer<TRouteContext>,
|
|
146
|
+
TLoaderData
|
|
147
|
+
>
|
|
148
|
+
} & (
|
|
155
149
|
| {
|
|
156
150
|
// Both or none
|
|
157
151
|
parseParams?: (
|
|
@@ -173,7 +167,7 @@ type BeforeLoadFn<
|
|
|
173
167
|
TFullSearchSchema extends Record<string, any>,
|
|
174
168
|
TParentRoute extends AnyRoute,
|
|
175
169
|
TAllParams,
|
|
176
|
-
|
|
170
|
+
TRouteContextReturn extends RouteContext,
|
|
177
171
|
> = (opts: {
|
|
178
172
|
search: TFullSearchSchema
|
|
179
173
|
abortController: AbortController
|
|
@@ -184,7 +178,7 @@ type BeforeLoadFn<
|
|
|
184
178
|
navigate: NavigateFn<AnyRoute>
|
|
185
179
|
buildLocation: BuildLocationFn<TParentRoute>
|
|
186
180
|
cause: 'preload' | 'enter' | 'stay'
|
|
187
|
-
}) => Promise<
|
|
181
|
+
}) => Promise<TRouteContextReturn> | TRouteContextReturn | void
|
|
188
182
|
|
|
189
183
|
export type UpdatableRouteOptions<
|
|
190
184
|
TFullSearchSchema extends Record<string, any>,
|
|
@@ -309,11 +303,19 @@ export type InferFullSearchSchemaInput<TRoute> = TRoute extends {
|
|
|
309
303
|
: {}
|
|
310
304
|
|
|
311
305
|
export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<
|
|
312
|
-
Assign<
|
|
306
|
+
Assign<
|
|
307
|
+
Omit<InferFullSearchSchema<TParentRoute>, keyof RootSearchSchema>,
|
|
308
|
+
TSearchSchema
|
|
309
|
+
>
|
|
313
310
|
>
|
|
314
311
|
|
|
315
312
|
export type ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed> =
|
|
316
|
-
Expand<
|
|
313
|
+
Expand<
|
|
314
|
+
Assign<
|
|
315
|
+
Omit<InferFullSearchSchemaInput<TParentRoute>, keyof RootSearchSchema>,
|
|
316
|
+
TSearchSchemaUsed
|
|
317
|
+
>
|
|
318
|
+
>
|
|
317
319
|
|
|
318
320
|
export interface AnyRoute
|
|
319
321
|
extends Route<
|
|
@@ -335,6 +337,7 @@ export interface AnyRoute
|
|
|
335
337
|
any,
|
|
336
338
|
any,
|
|
337
339
|
any,
|
|
340
|
+
any,
|
|
338
341
|
any
|
|
339
342
|
> {}
|
|
340
343
|
|
|
@@ -463,7 +466,12 @@ export class Route<
|
|
|
463
466
|
TParentRoute,
|
|
464
467
|
TParams
|
|
465
468
|
>,
|
|
466
|
-
|
|
469
|
+
TRouteContextReturn extends RouteConstraints['TRouteContext'] = RouteContext,
|
|
470
|
+
TRouteContext extends RouteConstraints['TRouteContext'] = [
|
|
471
|
+
TRouteContextReturn,
|
|
472
|
+
] extends [never]
|
|
473
|
+
? RouteContext
|
|
474
|
+
: TRouteContextReturn,
|
|
467
475
|
TAllContext extends Expand<
|
|
468
476
|
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
469
477
|
> = Expand<
|
|
@@ -487,6 +495,7 @@ export class Route<
|
|
|
487
495
|
TFullSearchSchema,
|
|
488
496
|
TParams,
|
|
489
497
|
TAllParams,
|
|
498
|
+
TRouteContextReturn,
|
|
490
499
|
TRouteContext,
|
|
491
500
|
TAllContext,
|
|
492
501
|
TLoaderDeps,
|
|
@@ -523,6 +532,7 @@ export class Route<
|
|
|
523
532
|
TFullSearchSchema,
|
|
524
533
|
TParams,
|
|
525
534
|
TAllParams,
|
|
535
|
+
TRouteContextReturn,
|
|
526
536
|
TRouteContext,
|
|
527
537
|
TAllContext,
|
|
528
538
|
TLoaderDeps,
|
|
@@ -575,6 +585,7 @@ export class Route<
|
|
|
575
585
|
TFullSearchSchema,
|
|
576
586
|
TParams,
|
|
577
587
|
TAllParams,
|
|
588
|
+
TRouteContextReturn,
|
|
578
589
|
TRouteContext,
|
|
579
590
|
TAllContext,
|
|
580
591
|
TLoaderDeps,
|
|
@@ -647,6 +658,7 @@ export class Route<
|
|
|
647
658
|
TFullSearchSchema,
|
|
648
659
|
TParams,
|
|
649
660
|
TAllParams,
|
|
661
|
+
TRouteContextReturn,
|
|
650
662
|
TRouteContext,
|
|
651
663
|
TAllContext,
|
|
652
664
|
TRouterContext,
|
|
@@ -682,6 +694,7 @@ export class Route<
|
|
|
682
694
|
TFullSearchSchema,
|
|
683
695
|
TParams,
|
|
684
696
|
TAllParams,
|
|
697
|
+
TRouteContextReturn,
|
|
685
698
|
TRouteContext,
|
|
686
699
|
TAllContext,
|
|
687
700
|
TRouterContext,
|
|
@@ -738,13 +751,14 @@ export class Route<
|
|
|
738
751
|
}
|
|
739
752
|
}
|
|
740
753
|
|
|
741
|
-
export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any>
|
|
754
|
+
export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>
|
|
742
755
|
|
|
743
756
|
export function rootRouteWithContext<TRouterContext extends {}>() {
|
|
744
757
|
return <
|
|
745
|
-
TSearchSchemaInput extends Record<string, any> =
|
|
746
|
-
TSearchSchema extends Record<string, any> =
|
|
747
|
-
TSearchSchemaUsed extends Record<string, any> =
|
|
758
|
+
TSearchSchemaInput extends Record<string, any> = RootSearchSchema,
|
|
759
|
+
TSearchSchema extends Record<string, any> = RootSearchSchema,
|
|
760
|
+
TSearchSchemaUsed extends Record<string, any> = RootSearchSchema,
|
|
761
|
+
TRouteContextReturn extends RouteContext = RouteContext,
|
|
748
762
|
TRouteContext extends RouteContext = RouteContext,
|
|
749
763
|
TLoaderDeps extends Record<string, any> = {},
|
|
750
764
|
TLoaderData extends any = unknown,
|
|
@@ -761,6 +775,7 @@ export function rootRouteWithContext<TRouterContext extends {}>() {
|
|
|
761
775
|
TSearchSchema, // TFullSearchSchema
|
|
762
776
|
{}, // TParams
|
|
763
777
|
{}, // TAllParams
|
|
778
|
+
TRouteContextReturn, // TRouteContextReturn
|
|
764
779
|
TRouteContext, // TRouteContext
|
|
765
780
|
Assign<TRouterContext, TRouteContext>, // TAllContext
|
|
766
781
|
TLoaderDeps,
|
|
@@ -777,6 +792,7 @@ export function rootRouteWithContext<TRouterContext extends {}>() {
|
|
|
777
792
|
TSearchSchemaInput,
|
|
778
793
|
TSearchSchema,
|
|
779
794
|
TSearchSchemaUsed,
|
|
795
|
+
TRouteContextReturn,
|
|
780
796
|
TRouteContext,
|
|
781
797
|
TRouterContext
|
|
782
798
|
> => {
|
|
@@ -784,10 +800,15 @@ export function rootRouteWithContext<TRouterContext extends {}>() {
|
|
|
784
800
|
}
|
|
785
801
|
}
|
|
786
802
|
|
|
803
|
+
export type RootSearchSchema = {
|
|
804
|
+
__TRootSearchSchema__: '__TRootSearchSchema__'
|
|
805
|
+
}
|
|
806
|
+
|
|
787
807
|
export class RootRoute<
|
|
788
|
-
TSearchSchemaInput extends Record<string, any> =
|
|
789
|
-
TSearchSchema extends Record<string, any> =
|
|
790
|
-
TSearchSchemaUsed extends Record<string, any> =
|
|
808
|
+
TSearchSchemaInput extends Record<string, any> = RootSearchSchema,
|
|
809
|
+
TSearchSchema extends Record<string, any> = RootSearchSchema,
|
|
810
|
+
TSearchSchemaUsed extends Record<string, any> = RootSearchSchema,
|
|
811
|
+
TRouteContextReturn extends RouteContext = RouteContext,
|
|
791
812
|
TRouteContext extends RouteContext = RouteContext,
|
|
792
813
|
TRouterContext extends {} = {},
|
|
793
814
|
TLoaderDeps extends Record<string, any> = {},
|
|
@@ -805,6 +826,7 @@ export class RootRoute<
|
|
|
805
826
|
TSearchSchema, // TFullSearchSchema
|
|
806
827
|
{}, // TParams
|
|
807
828
|
{}, // TAllParams
|
|
829
|
+
TRouteContextReturn, // TRouteContextReturn
|
|
808
830
|
TRouteContext, // TRouteContext
|
|
809
831
|
Expand<Assign<TRouterContext, TRouteContext>>, // TAllContext
|
|
810
832
|
TRouterContext, // TRouterContext
|
|
@@ -826,6 +848,7 @@ export class RootRoute<
|
|
|
826
848
|
TSearchSchema, // TFullSearchSchema
|
|
827
849
|
{}, // TParams
|
|
828
850
|
{}, // TAllParams
|
|
851
|
+
TRouteContextReturn, // TRouteContextReturn
|
|
829
852
|
TRouteContext, // TRouteContext
|
|
830
853
|
Assign<TRouterContext, TRouteContext>, // TAllContext
|
|
831
854
|
TLoaderDeps,
|
|
@@ -945,6 +968,7 @@ export class NotFoundRoute<
|
|
|
945
968
|
> = Expand<
|
|
946
969
|
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
947
970
|
>,
|
|
971
|
+
TRouteContextReturn extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
948
972
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
949
973
|
TLoaderDeps extends Record<string, any> = {},
|
|
950
974
|
TLoaderData extends any = unknown,
|
|
@@ -963,6 +987,7 @@ export class NotFoundRoute<
|
|
|
963
987
|
TFullSearchSchema,
|
|
964
988
|
{},
|
|
965
989
|
{},
|
|
990
|
+
TRouteContextReturn,
|
|
966
991
|
TRouteContext,
|
|
967
992
|
TAllContext,
|
|
968
993
|
TRouterContext,
|
|
@@ -984,6 +1009,7 @@ export class NotFoundRoute<
|
|
|
984
1009
|
TFullSearchSchema,
|
|
985
1010
|
{},
|
|
986
1011
|
{},
|
|
1012
|
+
TRouteContextReturn,
|
|
987
1013
|
TRouteContext,
|
|
988
1014
|
TAllContext,
|
|
989
1015
|
TLoaderDeps,
|