@tanstack/react-router 1.26.21 → 1.28.1

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.
Files changed (47) hide show
  1. package/dist/cjs/Matches.cjs.map +1 -1
  2. package/dist/cjs/fileRoute.cjs.map +1 -1
  3. package/dist/cjs/fileRoute.d.cts +9 -10
  4. package/dist/cjs/index.d.cts +1 -1
  5. package/dist/cjs/link.cjs.map +1 -1
  6. package/dist/cjs/link.d.cts +32 -24
  7. package/dist/cjs/path.cjs +17 -3
  8. package/dist/cjs/path.cjs.map +1 -1
  9. package/dist/cjs/path.d.cts +7 -1
  10. package/dist/cjs/route.cjs.map +1 -1
  11. package/dist/cjs/route.d.cts +42 -45
  12. package/dist/cjs/routeInfo.d.cts +5 -7
  13. package/dist/cjs/router.cjs +7 -1
  14. package/dist/cjs/router.cjs.map +1 -1
  15. package/dist/cjs/router.d.cts +2 -1
  16. package/dist/cjs/useParams.cjs.map +1 -1
  17. package/dist/cjs/utils.cjs.map +1 -1
  18. package/dist/cjs/utils.d.cts +5 -3
  19. package/dist/esm/Matches.js.map +1 -1
  20. package/dist/esm/fileRoute.d.ts +9 -10
  21. package/dist/esm/fileRoute.js.map +1 -1
  22. package/dist/esm/index.d.ts +1 -1
  23. package/dist/esm/link.d.ts +32 -24
  24. package/dist/esm/link.js.map +1 -1
  25. package/dist/esm/path.d.ts +7 -1
  26. package/dist/esm/path.js +17 -3
  27. package/dist/esm/path.js.map +1 -1
  28. package/dist/esm/route.d.ts +42 -45
  29. package/dist/esm/route.js.map +1 -1
  30. package/dist/esm/routeInfo.d.ts +5 -7
  31. package/dist/esm/router.d.ts +2 -1
  32. package/dist/esm/router.js +7 -1
  33. package/dist/esm/router.js.map +1 -1
  34. package/dist/esm/useParams.js.map +1 -1
  35. package/dist/esm/utils.d.ts +5 -3
  36. package/dist/esm/utils.js.map +1 -1
  37. package/package.json +1 -1
  38. package/src/Matches.tsx +2 -2
  39. package/src/fileRoute.ts +17 -36
  40. package/src/index.tsx +0 -1
  41. package/src/link.tsx +187 -82
  42. package/src/path.ts +23 -3
  43. package/src/route.ts +153 -186
  44. package/src/routeInfo.ts +5 -7
  45. package/src/router.ts +13 -6
  46. package/src/useParams.tsx +2 -2
  47. package/src/utils.ts +10 -6
package/src/routeInfo.ts CHANGED
@@ -4,7 +4,7 @@ import type { Expand, UnionToIntersection, UnionToTuple } from './utils'
4
4
  export type ParseRoute<TRouteTree, TAcc = TRouteTree> = TRouteTree extends {
5
5
  types: { children: infer TChildren }
6
6
  }
7
- ? TChildren extends Array<unknown>
7
+ ? TChildren extends ReadonlyArray<unknown>
8
8
  ? ParseRoute<TChildren[number], TAcc | TChildren[number]>
9
9
  : TAcc
10
10
  : TAcc
@@ -14,7 +14,7 @@ export type RoutesById<TRouteTree extends AnyRoute> = {
14
14
  }
15
15
 
16
16
  export type RouteById<TRouteTree extends AnyRoute, TId> = Extract<
17
- Extract<ParseRoute<TRouteTree>, { id: TId }>,
17
+ RoutesById<TRouteTree>[TId],
18
18
  AnyRoute
19
19
  >
20
20
 
@@ -56,11 +56,9 @@ type Reduce<TValue extends Array<any>, TResult = unknown> = TValue extends [
56
56
  : TResult
57
57
 
58
58
  export type FullSearchSchema<TRouteTree extends AnyRoute> = Partial<
59
- Expand<
60
- Reduce<UnionToTuple<ParseRoute<TRouteTree>['types']['fullSearchSchema']>>
61
- >
59
+ Reduce<UnionToTuple<ParseRoute<TRouteTree>['types']['fullSearchSchema']>>
62
60
  >
63
61
 
64
- export type AllParams<TRouteTree extends AnyRoute> = Expand<
65
- UnionToIntersection<ParseRoute<TRouteTree>['types']['allParams']>
62
+ export type AllParams<TRouteTree extends AnyRoute> = UnionToIntersection<
63
+ ParseRoute<TRouteTree>['types']['allParams']
66
64
  >
package/src/router.ts CHANGED
@@ -150,6 +150,7 @@ export interface RouterOptions<
150
150
  defaultNotFoundComponent?: NotFoundRouteComponent
151
151
  transformer?: RouterTransformer
152
152
  errorSerializer?: RouterErrorSerializer<TSerializedError>
153
+ trailingSlash?: 'always' | 'never' | 'preserve'
153
154
  }
154
155
 
155
156
  export interface RouterTransformer {
@@ -260,9 +261,9 @@ export function createRouter<
260
261
  }
261
262
 
262
263
  export class Router<
263
- TRouteTree extends AnyRoute = AnyRoute,
264
- TDehydrated extends Record<string, any> = Record<string, any>,
265
- TSerializedError extends Record<string, any> = Record<string, any>,
264
+ in out TRouteTree extends AnyRoute = AnyRoute,
265
+ in out TDehydrated extends Record<string, any> = Record<string, any>,
266
+ in out TSerializedError extends Record<string, any> = Record<string, any>,
266
267
  > {
267
268
  // Option-independent properties
268
269
  tempLocationKey: string | undefined = `${Math.round(
@@ -591,7 +592,13 @@ export class Router<
591
592
  }
592
593
 
593
594
  resolvePathWithBase = (from: string, path: string) => {
594
- return resolvePath(this.basepath, from, cleanPath(path))
595
+ const resolvedPath = resolvePath({
596
+ basepath: this.basepath,
597
+ base: from,
598
+ to: cleanPath(path),
599
+ trailingSlash: this.options.trailingSlash,
600
+ })
601
+ return resolvedPath
595
602
  }
596
603
 
597
604
  get looseRoutesById() {
@@ -1261,8 +1268,8 @@ export class Router<
1261
1268
  preload: !!preload,
1262
1269
  context: parentContext,
1263
1270
  location,
1264
- navigate: (opts) =>
1265
- this.navigate({ ...opts, from: match.pathname } as any),
1271
+ navigate: (opts: any) =>
1272
+ this.navigate({ ...opts, from: match.pathname }),
1266
1273
  buildLocation: this.buildLocation,
1267
1274
  cause: preload ? 'preload' : match.cause,
1268
1275
  })) ?? ({} as any)
package/src/useParams.tsx CHANGED
@@ -21,7 +21,7 @@ export function useParams<
21
21
  return useMatch({
22
22
  ...opts,
23
23
  select: (match) => {
24
- return opts.select ? opts.select(match.params) : match.params
24
+ return opts.select ? opts.select(match.params as TParams) : match.params
25
25
  },
26
- })
26
+ }) as TSelected
27
27
  }
package/src/utils.ts CHANGED
@@ -15,12 +15,14 @@ export type PickRequired<T> = {
15
15
  }
16
16
 
17
17
  // from https://stackoverflow.com/a/76458160
18
- export type WithoutEmpty<T> = T extends T ? ({} extends T ? never : T) : never
18
+ export type WithoutEmpty<T> = T extends any ? ({} extends T ? never : T) : never
19
19
 
20
20
  // export type Expand<T> = T
21
21
  export type Expand<T> = T extends object
22
22
  ? T extends infer O
23
- ? { [K in keyof O]: O[K] }
23
+ ? O extends Function
24
+ ? O
25
+ : { [K in keyof O]: O[K] }
24
26
  : never
25
27
  : T
26
28
 
@@ -36,10 +38,12 @@ export type DeepPartial<T> = T extends object
36
38
  }
37
39
  : T
38
40
 
39
- // eslint-disable-next-line @typescript-eslint/naming-convention
40
- export type MakeDifferenceOptional<T, U> = Omit<U, keyof T> &
41
- Partial<Pick<U, keyof T & keyof U>> &
42
- PickRequired<Omit<U, keyof PickRequired<T>>>
41
+ export type MakeDifferenceOptional<TLeft, TRight> = Omit<
42
+ TRight,
43
+ keyof TLeft
44
+ > & {
45
+ [K in keyof TLeft & keyof TRight]?: TRight[K]
46
+ }
43
47
 
44
48
  // from https://stackoverflow.com/a/53955431
45
49
  // eslint-disable-next-line @typescript-eslint/naming-convention