@tanstack/react-router 1.49.0 → 1.49.2
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.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +2 -3
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +1 -1
- package/dist/cjs/path.cjs +6 -9
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +9 -4
- package/dist/cjs/router.cjs +207 -194
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +18 -5
- package/dist/esm/fileRoute.d.ts +2 -3
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/link.d.ts +1 -1
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/path.js +6 -9
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/route.d.ts +9 -4
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +18 -5
- package/dist/esm/router.js +208 -195
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/fileRoute.ts +2 -1
- package/src/link.tsx +10 -6
- package/src/path.ts +7 -10
- package/src/route.ts +19 -4
- package/src/router.ts +44 -2
package/package.json
CHANGED
package/src/fileRoute.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
FileBaseRouteOptions,
|
|
18
18
|
ResolveAllParamsFromParent,
|
|
19
19
|
ResolveLoaderData,
|
|
20
|
+
ResolveParams,
|
|
20
21
|
ResolveRouteContext,
|
|
21
22
|
Route,
|
|
22
23
|
RouteConstraints,
|
|
@@ -73,7 +74,7 @@ export class FileRoute<
|
|
|
73
74
|
|
|
74
75
|
createRoute = <
|
|
75
76
|
TSearchValidator extends AnySearchValidator = DefaultSearchValidator,
|
|
76
|
-
TParams =
|
|
77
|
+
TParams = ResolveParams<TPath>,
|
|
77
78
|
TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>,
|
|
78
79
|
TRouteContextFn = AnyContext,
|
|
79
80
|
TBeforeLoadFn = AnyContext,
|
package/src/link.tsx
CHANGED
|
@@ -67,12 +67,16 @@ export type Split<TValue, TIncludeTrailingSlash = true> = TValue extends unknown
|
|
|
67
67
|
export type ParsePathParams<
|
|
68
68
|
T extends string,
|
|
69
69
|
TAcc = never,
|
|
70
|
-
> = T extends `${string}$${
|
|
71
|
-
?
|
|
72
|
-
?
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
> = T extends `${string}$${string}`
|
|
71
|
+
? T extends `${string}$${infer TPossiblyParam}`
|
|
72
|
+
? TPossiblyParam extends `${string}/${string}`
|
|
73
|
+
? TPossiblyParam extends `${infer TParam}/${infer TRest}`
|
|
74
|
+
? ParsePathParams<TRest, TParam extends '' ? TAcc : TParam | TAcc>
|
|
75
|
+
: never
|
|
76
|
+
: TPossiblyParam extends ''
|
|
77
|
+
? TAcc
|
|
78
|
+
: TPossiblyParam | TAcc
|
|
79
|
+
: TAcc
|
|
76
80
|
: TAcc
|
|
77
81
|
|
|
78
82
|
export type Join<T, TDelimiter extends string = '/'> = T extends []
|
package/src/path.ts
CHANGED
|
@@ -337,16 +337,13 @@ export function matchByPath(
|
|
|
337
337
|
|
|
338
338
|
if (routeSegment) {
|
|
339
339
|
if (routeSegment.type === 'wildcard') {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
return true
|
|
348
|
-
}
|
|
349
|
-
return false
|
|
340
|
+
const _splat = decodeURI(
|
|
341
|
+
joinPaths(baseSegments.slice(i).map((d) => d.value)),
|
|
342
|
+
)
|
|
343
|
+
// TODO: Deprecate *
|
|
344
|
+
params['*'] = _splat
|
|
345
|
+
params['_splat'] = _splat
|
|
346
|
+
return true
|
|
350
347
|
}
|
|
351
348
|
|
|
352
349
|
if (routeSegment.type === 'pathname') {
|
package/src/route.ts
CHANGED
|
@@ -87,15 +87,30 @@ export type RouteOptions<
|
|
|
87
87
|
NoInfer<TBeforeLoadFn>
|
|
88
88
|
>
|
|
89
89
|
|
|
90
|
+
export type ParseSplatParams<TPath extends string> = TPath extends `${string}$`
|
|
91
|
+
? '_splat'
|
|
92
|
+
: TPath extends `${string}$/${string}`
|
|
93
|
+
? '_splat'
|
|
94
|
+
: never
|
|
95
|
+
|
|
96
|
+
export interface SplatParams {
|
|
97
|
+
_splat?: string
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export type ResolveParams<TPath extends string> =
|
|
101
|
+
ParseSplatParams<TPath> extends never
|
|
102
|
+
? Record<ParsePathParams<TPath>, string>
|
|
103
|
+
: Record<ParsePathParams<TPath>, string> & SplatParams
|
|
104
|
+
|
|
90
105
|
export type ParseParamsFn<TPath extends string, TParams> = (
|
|
91
|
-
rawParams:
|
|
106
|
+
rawParams: ResolveParams<TPath>,
|
|
92
107
|
) => TParams extends Record<ParsePathParams<TPath>, any>
|
|
93
108
|
? TParams
|
|
94
109
|
: Record<ParsePathParams<TPath>, any>
|
|
95
110
|
|
|
96
111
|
export type StringifyParamsFn<TPath extends string, TParams> = (
|
|
97
112
|
params: TParams,
|
|
98
|
-
) =>
|
|
113
|
+
) => ResolveParams<TPath>
|
|
99
114
|
|
|
100
115
|
export type ParamsOptions<TPath extends string, TParams> = {
|
|
101
116
|
params?: {
|
|
@@ -817,7 +832,7 @@ export class Route<
|
|
|
817
832
|
TPath
|
|
818
833
|
>,
|
|
819
834
|
in out TSearchValidator extends AnySearchValidator = DefaultSearchValidator,
|
|
820
|
-
in out TParams =
|
|
835
|
+
in out TParams = ResolveParams<TPath>,
|
|
821
836
|
in out TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>,
|
|
822
837
|
in out TRouterContext = AnyContext,
|
|
823
838
|
in out TRouteContextFn = AnyContext,
|
|
@@ -1157,7 +1172,7 @@ export function createRoute<
|
|
|
1157
1172
|
TPath
|
|
1158
1173
|
>,
|
|
1159
1174
|
TSearchValidator extends AnySearchValidator = DefaultSearchValidator,
|
|
1160
|
-
TParams =
|
|
1175
|
+
TParams = ResolveParams<TPath>,
|
|
1161
1176
|
TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>,
|
|
1162
1177
|
TRouteContextFn = AnyContext,
|
|
1163
1178
|
TBeforeLoadFn = AnyContext,
|
package/src/router.ts
CHANGED
|
@@ -42,6 +42,7 @@ import type {
|
|
|
42
42
|
AnyContext,
|
|
43
43
|
AnyRoute,
|
|
44
44
|
AnyRouteWithContext,
|
|
45
|
+
AnySearchSchema,
|
|
45
46
|
BeforeLoadContextOptions,
|
|
46
47
|
ErrorRouteComponent,
|
|
47
48
|
LoaderFnContext,
|
|
@@ -588,6 +589,8 @@ export function createRouter<
|
|
|
588
589
|
>(options)
|
|
589
590
|
}
|
|
590
591
|
|
|
592
|
+
type MatchRoutesOpts = { preload?: boolean; throwOnError?: boolean }
|
|
593
|
+
|
|
591
594
|
export class Router<
|
|
592
595
|
in out TRouteTree extends AnyRoute,
|
|
593
596
|
in out TTrailingSlashOption extends TrailingSlashOption,
|
|
@@ -950,10 +953,49 @@ export class Router<
|
|
|
950
953
|
return this.routesById as Record<string, AnyRoute>
|
|
951
954
|
}
|
|
952
955
|
|
|
953
|
-
|
|
956
|
+
/**
|
|
957
|
+
@deprecated use the following signature instead
|
|
958
|
+
```ts
|
|
959
|
+
matchRoutes (
|
|
960
|
+
next: ParsedLocation,
|
|
961
|
+
opts?: { preload?: boolean; throwOnError?: boolean },
|
|
962
|
+
): Array<AnyRouteMatch>;
|
|
963
|
+
```
|
|
964
|
+
*/
|
|
965
|
+
public matchRoutes(
|
|
966
|
+
pathname: string,
|
|
967
|
+
locationSearch: AnySearchSchema,
|
|
968
|
+
opts?: MatchRoutesOpts,
|
|
969
|
+
): Array<AnyRouteMatch>
|
|
970
|
+
public matchRoutes(
|
|
971
|
+
next: ParsedLocation,
|
|
972
|
+
opts?: MatchRoutesOpts,
|
|
973
|
+
): Array<AnyRouteMatch>
|
|
974
|
+
|
|
975
|
+
public matchRoutes(
|
|
976
|
+
pathnameOrNext: string | ParsedLocation,
|
|
977
|
+
locationSearchOrOpts?:
|
|
978
|
+
| AnySearchSchema
|
|
979
|
+
| { preload?: boolean; throwOnError?: boolean },
|
|
980
|
+
opts?: { preload?: boolean; throwOnError?: boolean },
|
|
981
|
+
) {
|
|
982
|
+
if (typeof pathnameOrNext === 'string') {
|
|
983
|
+
return this.matchRoutesInternal(
|
|
984
|
+
{
|
|
985
|
+
pathname: pathnameOrNext,
|
|
986
|
+
search: locationSearchOrOpts,
|
|
987
|
+
} as ParsedLocation,
|
|
988
|
+
opts,
|
|
989
|
+
)
|
|
990
|
+
} else {
|
|
991
|
+
return this.matchRoutesInternal(pathnameOrNext, locationSearchOrOpts)
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
private matchRoutesInternal(
|
|
954
996
|
next: ParsedLocation,
|
|
955
997
|
opts?: { preload?: boolean; throwOnError?: boolean },
|
|
956
|
-
): Array<AnyRouteMatch>
|
|
998
|
+
): Array<AnyRouteMatch> {
|
|
957
999
|
let routeParams: Record<string, string> = {}
|
|
958
1000
|
|
|
959
1001
|
const foundRoute = this.flatRoutes.find((route) => {
|