@tanstack/router-core 0.0.1-beta.24 → 0.0.1-beta.26
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/packages/router-core/src/path.js +2 -2
- package/build/cjs/packages/router-core/src/path.js.map +1 -1
- package/build/cjs/packages/router-core/src/routeConfig.js +5 -2
- package/build/cjs/packages/router-core/src/routeConfig.js.map +1 -1
- package/build/cjs/packages/router-core/src/routeMatch.js.map +1 -1
- package/build/cjs/packages/router-core/src/router.js.map +1 -1
- package/build/cjs/packages/router-core/src/utils.js.map +1 -1
- package/build/esm/index.js +6 -4
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +136 -130
- package/build/types/index.d.ts +22 -23
- package/build/umd/index.development.js +6 -4
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/frameworks.ts +1 -0
- package/src/link.ts +2 -2
- package/src/path.ts +2 -2
- package/src/routeConfig.ts +72 -54
- package/src/routeInfo.ts +11 -6
- package/src/routeMatch.ts +3 -3
- package/src/router.ts +1 -1
- package/src/utils.ts +2 -2
package/package.json
CHANGED
package/src/frameworks.ts
CHANGED
package/src/link.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
RouteInfoByPath,
|
|
6
6
|
} from './routeInfo'
|
|
7
7
|
import { Location, LocationState } from './router'
|
|
8
|
-
import { Expand, NoInfer,
|
|
8
|
+
import { Expand, NoInfer, PickRequired, Updater } from './utils'
|
|
9
9
|
|
|
10
10
|
export type LinkInfo =
|
|
11
11
|
| {
|
|
@@ -58,7 +58,7 @@ export type Split<S, TIncludeTrailingSlash = true> = S extends unknown
|
|
|
58
58
|
: never
|
|
59
59
|
|
|
60
60
|
export type ParsePathParams<T extends string> = Split<T>[number] extends infer U
|
|
61
|
-
? U extends
|
|
61
|
+
? U extends `$${infer V}`
|
|
62
62
|
? V
|
|
63
63
|
: never
|
|
64
64
|
: never
|
package/src/path.ts
CHANGED
|
@@ -97,7 +97,7 @@ export function parsePathname(pathname?: string): Segment[] {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
if (part.charAt(0) === '
|
|
100
|
+
if (part.charAt(0) === '$') {
|
|
101
101
|
return {
|
|
102
102
|
type: 'param',
|
|
103
103
|
value: part,
|
|
@@ -215,7 +215,7 @@ export function matchByPath(
|
|
|
215
215
|
if (baseSegment?.value === '/') {
|
|
216
216
|
return false
|
|
217
217
|
}
|
|
218
|
-
if (
|
|
218
|
+
if (baseSegment.value.charAt(0) !== '$') {
|
|
219
219
|
params[routeSegment.value.substring(1)] = baseSegment.value
|
|
220
220
|
}
|
|
221
221
|
}
|
package/src/routeConfig.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import invariant from 'tiny-invariant'
|
|
1
2
|
import { GetFrameworkGeneric } from './frameworks'
|
|
2
3
|
import { ParsePathParams } from './link'
|
|
3
4
|
import { joinPaths, trimPath, trimPathRight } from './path'
|
|
@@ -56,7 +57,7 @@ export type LoaderFn<
|
|
|
56
57
|
TAllParams extends AnyPathParams = {},
|
|
57
58
|
> = (
|
|
58
59
|
loaderContext: LoaderContext<TFullSearchSchema, TAllParams>,
|
|
59
|
-
) => Promise<TRouteLoaderData>
|
|
60
|
+
) => TRouteLoaderData | Promise<TRouteLoaderData>
|
|
60
61
|
|
|
61
62
|
export interface LoaderContext<
|
|
62
63
|
TFullSearchSchema extends AnySearchSchema = {},
|
|
@@ -81,6 +82,7 @@ export type RouteOptions<
|
|
|
81
82
|
TPath extends string = string,
|
|
82
83
|
TParentRouteLoaderData extends AnyLoaderData = {},
|
|
83
84
|
TRouteLoaderData extends AnyLoaderData = {},
|
|
85
|
+
TParentLoaderData extends AnyLoaderData = {},
|
|
84
86
|
TLoaderData extends AnyLoaderData = {},
|
|
85
87
|
TActionPayload = unknown,
|
|
86
88
|
TActionResponse = unknown,
|
|
@@ -114,7 +116,7 @@ export type RouteOptions<
|
|
|
114
116
|
// The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`
|
|
115
117
|
component?: GetFrameworkGeneric<'Component'> // , NoInfer<TParentLoaderData>>
|
|
116
118
|
// The content to be rendered when the route encounters an error
|
|
117
|
-
errorComponent?: GetFrameworkGeneric<'
|
|
119
|
+
errorComponent?: GetFrameworkGeneric<'ErrorComponent'> // , NoInfer<TParentLoaderData>>
|
|
118
120
|
// If supported by your framework, the content to be rendered as the fallback content until the route is ready to render
|
|
119
121
|
pendingComponent?: GetFrameworkGeneric<'Component'> //, NoInfer<TParentLoaderData>>
|
|
120
122
|
// An asynchronous function responsible for preparing or fetching data for the route before it is rendered
|
|
@@ -176,6 +178,7 @@ export interface RouteConfig<
|
|
|
176
178
|
TFullPath extends string = string,
|
|
177
179
|
TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData,
|
|
178
180
|
TRouteLoaderData extends AnyLoaderData = AnyLoaderData,
|
|
181
|
+
TParentLoaderData extends AnyLoaderData = {},
|
|
179
182
|
TLoaderData extends AnyLoaderData = AnyLoaderData,
|
|
180
183
|
TActionPayload = unknown,
|
|
181
184
|
TActionResponse = unknown,
|
|
@@ -183,10 +186,7 @@ export interface RouteConfig<
|
|
|
183
186
|
TSearchSchema extends AnySearchSchema = {},
|
|
184
187
|
TFullSearchSchema extends AnySearchSchema = {},
|
|
185
188
|
TParentParams extends AnyPathParams = {},
|
|
186
|
-
TParams extends
|
|
187
|
-
ParsePathParams<TPath>,
|
|
188
|
-
string
|
|
189
|
-
>,
|
|
189
|
+
TParams extends AnyPathParams = {},
|
|
190
190
|
TAllParams extends AnyPathParams = {},
|
|
191
191
|
TKnownChildren = unknown,
|
|
192
192
|
> {
|
|
@@ -199,6 +199,7 @@ export interface RouteConfig<
|
|
|
199
199
|
TPath,
|
|
200
200
|
TParentRouteLoaderData,
|
|
201
201
|
TRouteLoaderData,
|
|
202
|
+
TParentLoaderData,
|
|
202
203
|
TLoaderData,
|
|
203
204
|
TActionPayload,
|
|
204
205
|
TActionResponse,
|
|
@@ -224,6 +225,7 @@ export interface RouteConfig<
|
|
|
224
225
|
TFullPath,
|
|
225
226
|
TParentRouteLoaderData,
|
|
226
227
|
TRouteLoaderData,
|
|
228
|
+
TParentLoaderData,
|
|
227
229
|
TLoaderData,
|
|
228
230
|
TActionPayload,
|
|
229
231
|
TActionResponse,
|
|
@@ -236,52 +238,67 @@ export interface RouteConfig<
|
|
|
236
238
|
TNewChildren
|
|
237
239
|
>
|
|
238
240
|
>
|
|
239
|
-
|
|
241
|
+
createRoute: CreateRouteConfigFn<
|
|
242
|
+
false,
|
|
240
243
|
TId,
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
244
|
+
TFullPath,
|
|
245
|
+
TRouteLoaderData,
|
|
246
|
+
TLoaderData,
|
|
247
|
+
TFullSearchSchema,
|
|
248
|
+
TAllParams
|
|
249
|
+
>
|
|
250
|
+
generate: GenerateFn<
|
|
251
|
+
TRouteId,
|
|
252
|
+
TPath,
|
|
253
|
+
TParentRouteLoaderData,
|
|
254
|
+
TParentLoaderData,
|
|
255
|
+
TParentSearchSchema,
|
|
256
|
+
TParentParams
|
|
257
|
+
>
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
type GenerateFn<
|
|
261
|
+
TRouteId extends string = string,
|
|
262
|
+
TPath extends string = string,
|
|
263
|
+
TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData,
|
|
264
|
+
TParentLoaderData extends AnyLoaderData = {},
|
|
265
|
+
TParentSearchSchema extends {} = {},
|
|
266
|
+
TParentParams extends AnyPathParams = {},
|
|
267
|
+
> = <
|
|
268
|
+
TRouteLoaderData extends AnyLoaderData = AnyLoaderData,
|
|
269
|
+
TActionPayload = unknown,
|
|
270
|
+
TActionResponse = unknown,
|
|
271
|
+
TSearchSchema extends AnySearchSchema = {},
|
|
272
|
+
TParams extends Record<ParsePathParams<TPath>, unknown> = Record<
|
|
273
|
+
ParsePathParams<TPath>,
|
|
274
|
+
string
|
|
275
|
+
>,
|
|
276
|
+
TAllParams extends AnyPathParams extends TParams
|
|
277
|
+
? Record<ParsePathParams<TPath>, string>
|
|
278
|
+
: NoInfer<TParams> = AnyPathParams extends TParams
|
|
279
|
+
? Record<ParsePathParams<TPath>, string>
|
|
280
|
+
: NoInfer<TParams>,
|
|
281
|
+
>(
|
|
282
|
+
options: Omit<
|
|
283
|
+
RouteOptions<
|
|
258
284
|
TRouteId,
|
|
259
285
|
TPath,
|
|
260
|
-
TFullPath,
|
|
261
286
|
TParentRouteLoaderData,
|
|
262
287
|
TRouteLoaderData,
|
|
263
|
-
|
|
288
|
+
TParentLoaderData,
|
|
289
|
+
Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,
|
|
264
290
|
TActionPayload,
|
|
265
291
|
TActionResponse,
|
|
266
292
|
TParentSearchSchema,
|
|
267
293
|
TSearchSchema,
|
|
268
|
-
|
|
294
|
+
Expand<TParentSearchSchema & TSearchSchema>,
|
|
269
295
|
TParentParams,
|
|
270
296
|
TParams,
|
|
271
|
-
TAllParams
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
false,
|
|
277
|
-
TId,
|
|
278
|
-
TFullPath,
|
|
279
|
-
TRouteLoaderData,
|
|
280
|
-
TLoaderData,
|
|
281
|
-
TFullSearchSchema,
|
|
282
|
-
TAllParams
|
|
283
|
-
>
|
|
284
|
-
}
|
|
297
|
+
Expand<TParentParams & TAllParams>
|
|
298
|
+
>,
|
|
299
|
+
'path'
|
|
300
|
+
>,
|
|
301
|
+
) => void
|
|
285
302
|
|
|
286
303
|
type CreateRouteConfigFn<
|
|
287
304
|
TIsRoot extends boolean = false,
|
|
@@ -321,7 +338,8 @@ type CreateRouteConfigFn<
|
|
|
321
338
|
TPath,
|
|
322
339
|
TParentRouteLoaderData,
|
|
323
340
|
TRouteLoaderData,
|
|
324
|
-
|
|
341
|
+
TParentLoaderData,
|
|
342
|
+
Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,
|
|
325
343
|
TActionPayload,
|
|
326
344
|
TActionResponse,
|
|
327
345
|
TParentSearchSchema,
|
|
@@ -338,7 +356,8 @@ type CreateRouteConfigFn<
|
|
|
338
356
|
TPath,
|
|
339
357
|
TParentRouteLoaderData,
|
|
340
358
|
TRouteLoaderData,
|
|
341
|
-
|
|
359
|
+
TParentLoaderData,
|
|
360
|
+
Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,
|
|
342
361
|
TActionPayload,
|
|
343
362
|
TActionResponse,
|
|
344
363
|
TParentSearchSchema,
|
|
@@ -359,7 +378,8 @@ type CreateRouteConfigFn<
|
|
|
359
378
|
string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>,
|
|
360
379
|
TParentRouteLoaderData,
|
|
361
380
|
TRouteLoaderData,
|
|
362
|
-
|
|
381
|
+
TParentLoaderData,
|
|
382
|
+
Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,
|
|
363
383
|
TActionPayload,
|
|
364
384
|
TActionResponse,
|
|
365
385
|
TParentSearchSchema,
|
|
@@ -403,6 +423,7 @@ export interface AnyRouteConfig
|
|
|
403
423
|
any,
|
|
404
424
|
any,
|
|
405
425
|
any,
|
|
426
|
+
any,
|
|
406
427
|
any
|
|
407
428
|
> {}
|
|
408
429
|
|
|
@@ -423,6 +444,7 @@ export interface AnyRouteConfigWithChildren<TChildren>
|
|
|
423
444
|
any,
|
|
424
445
|
any,
|
|
425
446
|
any,
|
|
447
|
+
any,
|
|
426
448
|
TChildren
|
|
427
449
|
> {}
|
|
428
450
|
|
|
@@ -486,19 +508,15 @@ export const createRouteConfig: CreateRouteConfigFn<true> = (
|
|
|
486
508
|
fullPath: fullPath as any,
|
|
487
509
|
options: options as any,
|
|
488
510
|
children,
|
|
489
|
-
createChildren: (cb: any) =>
|
|
490
|
-
createRouteConfig(
|
|
491
|
-
options,
|
|
492
|
-
cb((childOptions: any) =>
|
|
493
|
-
createRouteConfig(childOptions, undefined, false, id, fullPath),
|
|
494
|
-
),
|
|
495
|
-
false,
|
|
496
|
-
parentId,
|
|
497
|
-
parentPath,
|
|
498
|
-
),
|
|
499
511
|
addChildren: (children: any) =>
|
|
500
512
|
createRouteConfig(options, children, false, parentId, parentPath),
|
|
501
513
|
createRoute: (childOptions: any) =>
|
|
502
514
|
createRouteConfig(childOptions, undefined, false, id, fullPath) as any,
|
|
515
|
+
generate: () => {
|
|
516
|
+
invariant(
|
|
517
|
+
false,
|
|
518
|
+
`routeConfig.generate() is used by TanStack Router's file-based routing code generation and should not actually be called during runtime. `,
|
|
519
|
+
)
|
|
520
|
+
},
|
|
503
521
|
}
|
|
504
522
|
}
|
package/src/routeInfo.ts
CHANGED
|
@@ -60,13 +60,15 @@ type ParseRouteChild<TRouteConfig, TId> = TRouteConfig & {
|
|
|
60
60
|
? ParseRouteConfig<TRouteConfig>
|
|
61
61
|
: never
|
|
62
62
|
|
|
63
|
+
// Generics!
|
|
63
64
|
export type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<
|
|
64
65
|
infer TId,
|
|
65
66
|
infer TRouteId,
|
|
66
67
|
infer TPath,
|
|
67
68
|
infer TFullPath,
|
|
68
|
-
infer
|
|
69
|
+
infer TParentRouteLoaderData,
|
|
69
70
|
infer TRouteLoaderData,
|
|
71
|
+
infer TParentLoaderData,
|
|
70
72
|
infer TLoaderData,
|
|
71
73
|
infer TActionPayload,
|
|
72
74
|
infer TActionResponse,
|
|
@@ -85,8 +87,9 @@ export type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<
|
|
|
85
87
|
TRouteId,
|
|
86
88
|
TPath,
|
|
87
89
|
TFullPath,
|
|
88
|
-
|
|
90
|
+
TParentRouteLoaderData,
|
|
89
91
|
TRouteLoaderData,
|
|
92
|
+
TParentLoaderData,
|
|
90
93
|
TLoaderData,
|
|
91
94
|
TActionPayload,
|
|
92
95
|
TActionResponse,
|
|
@@ -116,6 +119,7 @@ export interface RoutesInfoInner<
|
|
|
116
119
|
any,
|
|
117
120
|
any,
|
|
118
121
|
any,
|
|
122
|
+
any,
|
|
119
123
|
any
|
|
120
124
|
> = RouteInfo,
|
|
121
125
|
TRouteInfoById = { '/': TRouteInfo } & {
|
|
@@ -154,6 +158,7 @@ export interface AnyRouteInfo
|
|
|
154
158
|
any,
|
|
155
159
|
any,
|
|
156
160
|
any,
|
|
161
|
+
any,
|
|
157
162
|
any
|
|
158
163
|
> {}
|
|
159
164
|
|
|
@@ -164,6 +169,7 @@ export interface RouteInfo<
|
|
|
164
169
|
TFullPath extends string = string,
|
|
165
170
|
TParentRouteLoaderData extends AnyLoaderData = {},
|
|
166
171
|
TRouteLoaderData extends AnyLoaderData = {},
|
|
172
|
+
TParentLoaderData extends AnyLoaderData = {},
|
|
167
173
|
TLoaderData extends AnyLoaderData = {},
|
|
168
174
|
TActionPayload = unknown,
|
|
169
175
|
TActionResponse = unknown,
|
|
@@ -171,10 +177,7 @@ export interface RouteInfo<
|
|
|
171
177
|
TSearchSchema extends AnySearchSchema = {},
|
|
172
178
|
TFullSearchSchema extends AnySearchSchema = {},
|
|
173
179
|
TParentParams extends AnyPathParams = {},
|
|
174
|
-
TParams extends
|
|
175
|
-
ParsePathParams<TPath>,
|
|
176
|
-
string
|
|
177
|
-
>,
|
|
180
|
+
TParams extends AnyPathParams = {},
|
|
178
181
|
TAllParams extends AnyPathParams = {},
|
|
179
182
|
> {
|
|
180
183
|
id: TId
|
|
@@ -183,6 +186,7 @@ export interface RouteInfo<
|
|
|
183
186
|
fullPath: TFullPath
|
|
184
187
|
parentRouteLoaderData: TParentRouteLoaderData
|
|
185
188
|
routeLoaderData: TRouteLoaderData
|
|
189
|
+
parentLoaderData: TParentLoaderData
|
|
186
190
|
loaderData: TLoaderData
|
|
187
191
|
actionPayload: TActionPayload
|
|
188
192
|
actionResponse: TActionResponse
|
|
@@ -196,6 +200,7 @@ export interface RouteInfo<
|
|
|
196
200
|
TPath,
|
|
197
201
|
TParentRouteLoaderData,
|
|
198
202
|
TRouteLoaderData,
|
|
203
|
+
TParentLoaderData,
|
|
199
204
|
TLoaderData,
|
|
200
205
|
TActionPayload,
|
|
201
206
|
TActionResponse,
|
package/src/routeMatch.ts
CHANGED
|
@@ -30,9 +30,9 @@ export interface RouteMatch<
|
|
|
30
30
|
isFetching: boolean
|
|
31
31
|
invalidAt: number
|
|
32
32
|
__: {
|
|
33
|
-
component?: GetFrameworkGeneric<'Component'>
|
|
34
|
-
errorComponent?: GetFrameworkGeneric<'
|
|
35
|
-
pendingComponent?: GetFrameworkGeneric<'Component'>
|
|
33
|
+
component?: GetFrameworkGeneric<'Component'>
|
|
34
|
+
errorComponent?: GetFrameworkGeneric<'ErrorComponent'>
|
|
35
|
+
pendingComponent?: GetFrameworkGeneric<'Component'>
|
|
36
36
|
loadPromise?: Promise<void>
|
|
37
37
|
componentsPromise?: Promise<void>
|
|
38
38
|
dataPromise?: Promise<TRouteInfo['routeLoaderData']>
|
package/src/router.ts
CHANGED
|
@@ -91,7 +91,7 @@ export interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
|
|
|
91
91
|
defaultPreloadGcMaxAge?: number
|
|
92
92
|
defaultPreloadDelay?: number
|
|
93
93
|
defaultComponent?: GetFrameworkGeneric<'Component'>
|
|
94
|
-
defaultErrorComponent?: GetFrameworkGeneric<'
|
|
94
|
+
defaultErrorComponent?: GetFrameworkGeneric<'ErrorComponent'>
|
|
95
95
|
defaultPendingComponent?: GetFrameworkGeneric<'Component'>
|
|
96
96
|
defaultLoaderMaxAge?: number
|
|
97
97
|
defaultLoaderGcMaxAge?: number
|
package/src/utils.ts
CHANGED
|
@@ -40,9 +40,9 @@ export type DeepAwaited<T> = T extends Promise<infer A>
|
|
|
40
40
|
: T
|
|
41
41
|
|
|
42
42
|
export type PathParamMask<TRoutePath extends string> =
|
|
43
|
-
TRoutePath extends `${infer L}
|
|
43
|
+
TRoutePath extends `${infer L}/$${infer C}/${infer R}`
|
|
44
44
|
? PathParamMask<`${L}/${string}/${R}`>
|
|
45
|
-
: TRoutePath extends `${infer L}
|
|
45
|
+
: TRoutePath extends `${infer L}/$${infer C}`
|
|
46
46
|
? PathParamMask<`${L}/${string}`>
|
|
47
47
|
: TRoutePath
|
|
48
48
|
|