@tanstack/react-router 1.31.29 → 1.32.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.
Files changed (82) hide show
  1. package/dist/cjs/Matches.d.cts +6 -9
  2. package/dist/cjs/RouterProvider.d.cts +6 -6
  3. package/dist/cjs/awaited.d.cts +1 -1
  4. package/dist/cjs/defer.d.cts +1 -0
  5. package/dist/cjs/fileRoute.cjs.map +1 -1
  6. package/dist/cjs/fileRoute.d.cts +38 -79
  7. package/dist/cjs/index.cjs +2 -0
  8. package/dist/cjs/index.cjs.map +1 -1
  9. package/dist/cjs/index.d.cts +4 -3
  10. package/dist/cjs/lazyRouteComponent.d.cts +2 -1
  11. package/dist/cjs/link.cjs.map +1 -1
  12. package/dist/cjs/link.d.cts +56 -50
  13. package/dist/cjs/location.d.cts +3 -2
  14. package/dist/cjs/not-found.d.cts +2 -2
  15. package/dist/cjs/path.d.cts +3 -2
  16. package/dist/cjs/redirects.d.cts +5 -4
  17. package/dist/cjs/route.cjs +1 -1
  18. package/dist/cjs/route.cjs.map +1 -1
  19. package/dist/cjs/route.d.cts +59 -52
  20. package/dist/cjs/routeInfo.d.cts +12 -11
  21. package/dist/cjs/router.cjs +2 -2
  22. package/dist/cjs/router.cjs.map +1 -1
  23. package/dist/cjs/router.d.cts +19 -20
  24. package/dist/cjs/routerContext.d.cts +1 -1
  25. package/dist/cjs/scroll-restoration.d.cts +2 -1
  26. package/dist/cjs/searchParams.d.cts +2 -1
  27. package/dist/cjs/useBlocker.d.cts +3 -2
  28. package/dist/cjs/useLocation.cjs +10 -0
  29. package/dist/cjs/useLocation.cjs.map +1 -0
  30. package/dist/cjs/useLocation.d.cts +5 -0
  31. package/dist/cjs/useNavigate.cjs.map +1 -1
  32. package/dist/cjs/useNavigate.d.cts +5 -4
  33. package/dist/cjs/useParams.d.cts +5 -5
  34. package/dist/cjs/useRouteContext.d.cts +5 -4
  35. package/dist/cjs/useRouter.d.cts +2 -1
  36. package/dist/cjs/useRouterState.d.cts +2 -1
  37. package/dist/cjs/useSearch.d.cts +5 -4
  38. package/dist/esm/Matches.d.ts +6 -9
  39. package/dist/esm/RouterProvider.d.ts +6 -6
  40. package/dist/esm/awaited.d.ts +1 -1
  41. package/dist/esm/defer.d.ts +1 -0
  42. package/dist/esm/fileRoute.d.ts +38 -79
  43. package/dist/esm/fileRoute.js.map +1 -1
  44. package/dist/esm/index.d.ts +4 -3
  45. package/dist/esm/index.js +2 -0
  46. package/dist/esm/index.js.map +1 -1
  47. package/dist/esm/lazyRouteComponent.d.ts +2 -1
  48. package/dist/esm/link.d.ts +56 -50
  49. package/dist/esm/link.js.map +1 -1
  50. package/dist/esm/location.d.ts +3 -2
  51. package/dist/esm/not-found.d.ts +2 -2
  52. package/dist/esm/path.d.ts +3 -2
  53. package/dist/esm/redirects.d.ts +5 -4
  54. package/dist/esm/route.d.ts +59 -52
  55. package/dist/esm/route.js +1 -1
  56. package/dist/esm/route.js.map +1 -1
  57. package/dist/esm/routeInfo.d.ts +12 -11
  58. package/dist/esm/router.d.ts +19 -20
  59. package/dist/esm/router.js +2 -2
  60. package/dist/esm/router.js.map +1 -1
  61. package/dist/esm/routerContext.d.ts +1 -1
  62. package/dist/esm/scroll-restoration.d.ts +2 -1
  63. package/dist/esm/searchParams.d.ts +2 -1
  64. package/dist/esm/useBlocker.d.ts +3 -2
  65. package/dist/esm/useLocation.d.ts +5 -0
  66. package/dist/esm/useLocation.js +10 -0
  67. package/dist/esm/useLocation.js.map +1 -0
  68. package/dist/esm/useNavigate.d.ts +5 -4
  69. package/dist/esm/useNavigate.js.map +1 -1
  70. package/dist/esm/useParams.d.ts +5 -5
  71. package/dist/esm/useRouteContext.d.ts +5 -4
  72. package/dist/esm/useRouter.d.ts +2 -1
  73. package/dist/esm/useRouterState.d.ts +2 -1
  74. package/dist/esm/useSearch.d.ts +5 -4
  75. package/package.json +2 -10
  76. package/src/fileRoute.ts +26 -104
  77. package/src/index.tsx +1 -8
  78. package/src/link.tsx +205 -156
  79. package/src/route.ts +121 -106
  80. package/src/routeInfo.ts +24 -22
  81. package/src/useLocation.tsx +15 -0
  82. package/src/useNavigate.tsx +2 -2
@@ -1,4 +1,5 @@
1
- import type { AnyRouter, RegisteredRouter } from './router.js';
1
+ import { AnyRouter, RegisteredRouter } from './router.js';
2
+
2
3
  export declare function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {
3
4
  warn?: boolean;
4
5
  }): TRouter;
@@ -1,4 +1,5 @@
1
- import type { AnyRouter, RegisteredRouter, RouterState } from './router.js';
1
+ import { AnyRouter, RegisteredRouter, RouterState } from './router.js';
2
+
2
3
  export declare function useRouterState<TRouter extends AnyRouter = RegisteredRouter, TSelected = RouterState<TRouter['routeTree']>>(opts?: {
3
4
  router?: TRouter;
4
5
  select: (state: RouterState<RegisteredRouter['routeTree']>) => TSelected;
@@ -1,7 +1,8 @@
1
- import type { AnyRoute, RootSearchSchema } from './route.js';
2
- import type { FullSearchSchema, RouteById, RouteIds } from './routeInfo.js';
3
- import type { RegisteredRouter } from './router.js';
4
- import type { StrictOrFrom } from './utils.js';
1
+ import { AnyRoute, RootSearchSchema } from './route.js';
2
+ import { FullSearchSchema, RouteById, RouteIds } from './routeInfo.js';
3
+ import { RegisteredRouter } from './router.js';
4
+ import { StrictOrFrom } from './utils.js';
5
+
5
6
  export declare function useSearch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TReturnIntersection extends boolean = false, TSearch = TReturnIntersection extends false ? Exclude<RouteById<TRouteTree, TFrom>['types']['fullSearchSchema'], RootSearchSchema> : Partial<Omit<FullSearchSchema<TRouteTree>, keyof RootSearchSchema>>, TSelected = TSearch>(opts: StrictOrFrom<TFrom, TReturnIntersection> & {
6
7
  select?: (search: TSearch) => TSelected;
7
8
  }): TSelected;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.31.29",
3
+ "version": "1.32.2",
4
4
  "description": "",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -66,13 +66,5 @@
66
66
  "react": ">=16.8",
67
67
  "react-dom": ">=16.8"
68
68
  },
69
- "scripts": {
70
- "clean": "rimraf ./dist && rimraf ./coverage",
71
- "test:eslint": "eslint --ext .ts,.tsx ./src",
72
- "test:types": "tsc --noEmit",
73
- "test:unit": "vitest --typecheck",
74
- "test:unit:dev": "pnpm run test:unit --watch",
75
- "test:build": "publint --strict",
76
- "build": "vite build"
77
- }
69
+ "scripts": {}
78
70
  }
package/src/fileRoute.ts CHANGED
@@ -11,10 +11,13 @@ import type {
11
11
  AnyRoute,
12
12
  AnySearchSchema,
13
13
  FileBaseRouteOptions,
14
- MergeFromFromParent,
15
- ResolveFullPath,
14
+ ResolveAllContext,
15
+ ResolveAllParamsFromParent,
16
16
  ResolveFullSearchSchema,
17
17
  ResolveFullSearchSchemaInput,
18
+ ResolveLoaderData,
19
+ ResolveRouteContext,
20
+ ResolveSearchSchemaUsed,
18
21
  RootRouteId,
19
22
  Route,
20
23
  RouteConstraints,
@@ -36,79 +39,13 @@ export interface FileRoutesByPath {
36
39
  // }
37
40
  }
38
41
 
39
- type Replace<
40
- TValue extends string,
41
- TFrom extends string,
42
- TTo extends string,
43
- TAcc extends string = '',
44
- > = TValue extends `${infer Start}${TFrom}${infer Rest}`
45
- ? Replace<Rest, TFrom, TTo, `${TAcc}${Start}${TTo}`>
46
- : `${TAcc}${TValue}`
47
-
48
- export type TrimLeft<
49
- TValue extends string,
50
- TStartsWith extends string,
51
- > = TValue extends `${TStartsWith}${infer U}` ? U : TValue
52
-
53
- export type TrimRight<
54
- TValue extends string,
55
- TEndsWith extends string,
56
- > = TValue extends `${infer U}${TEndsWith}` ? U : TValue
57
-
58
- export type Trim<TValue extends string, TFind extends string> = TrimLeft<
59
- TrimRight<TValue, TFind>,
60
- TFind
61
- >
62
-
63
- export type RemoveUnderScores<T extends string> = Replace<
64
- Replace<TrimRight<TrimLeft<T, '/_'>, '_'>, '_/', '/'>,
65
- '/_',
66
- '/'
67
- >
68
-
69
- type RemoveRouteGroups<T extends string> =
70
- T extends `${infer Before}(${string})${infer After}`
71
- ? RemoveRouteGroups<`${Before}${After}`>
72
- : T
73
-
74
- type NormalizeSlashes<T extends string> =
75
- T extends `${infer Before}//${infer After}`
76
- ? NormalizeSlashes<`${Before}/${After}`>
77
- : T
78
-
79
- export type ResolveFilePath<
80
- TParentRoute extends AnyRoute,
81
- TFilePath extends string,
82
- > = TParentRoute['id'] extends RootRouteId
83
- ? TrimPathLeft<TFilePath>
84
- : TFilePath extends `${TParentRoute['types']['customId']}${infer TRest}`
85
- ? TRest
86
- : TFilePath
87
-
88
- export type FileRoutePath<
89
- TParentRoute extends AnyRoute,
90
- TFilePath extends string,
91
- TResolvedFilePath = ResolveFilePath<TParentRoute, TFilePath>,
92
- > = TResolvedFilePath extends `_${string}`
93
- ? ''
94
- : TResolvedFilePath extends `/_${string}`
95
- ? ''
96
- : TResolvedFilePath
97
-
98
42
  export function createFileRoute<
99
43
  TFilePath extends keyof FileRoutesByPath,
100
44
  TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],
101
- TId extends RouteConstraints['TId'] = NormalizeSlashes<
102
- RemoveRouteGroups<TFilePath>
103
- >,
104
- TPath extends RouteConstraints['TPath'] = FileRoutePath<
105
- TParentRoute,
106
- TFilePath
107
- >,
108
- TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
109
- TParentRoute,
110
- NormalizeSlashes<RemoveRouteGroups<RemoveUnderScores<TPath>>>
111
- >,
45
+ TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],
46
+ TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],
47
+ TFullPath extends
48
+ RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath'],
112
49
  >(path: TFilePath) {
113
50
  return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {
114
51
  silent: true,
@@ -122,15 +59,10 @@ export function createFileRoute<
122
59
  export class FileRoute<
123
60
  TFilePath extends keyof FileRoutesByPath,
124
61
  TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],
125
- TId extends RouteConstraints['TId'] = TFilePath,
126
- TPath extends RouteConstraints['TPath'] = FileRoutePath<
127
- TParentRoute,
128
- TFilePath
129
- >,
130
- TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
131
- TParentRoute,
132
- RemoveUnderScores<TPath>
133
- >,
62
+ TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],
63
+ TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],
64
+ TFullPath extends
65
+ RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath'],
134
66
  > {
135
67
  silent?: boolean
136
68
 
@@ -142,37 +74,27 @@ export class FileRoute<
142
74
  }
143
75
 
144
76
  createRoute = <
145
- TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},
146
- TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
147
- TSearchSchemaUsed = TSearchSchemaInput extends SearchSchemaInput
148
- ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>
149
- : TSearchSchema,
77
+ TSearchSchemaInput = {},
78
+ TSearchSchema = {},
79
+ TSearchSchemaUsed = ResolveSearchSchemaUsed<
80
+ TSearchSchemaInput,
81
+ TSearchSchema
82
+ >,
150
83
  TFullSearchSchemaInput = ResolveFullSearchSchemaInput<
151
84
  TParentRoute,
152
85
  TSearchSchemaUsed
153
86
  >,
154
87
  TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
155
88
  TParams = Record<ParsePathParams<TPath>, string>,
156
- TAllParams = MergeFromFromParent<
157
- TParentRoute['types']['allParams'],
158
- TParams
159
- >,
160
- TRouteContextReturn extends
161
- RouteConstraints['TRouteContext'] = RouteContext,
162
- TRouteContext = [TRouteContextReturn] extends [never]
163
- ? RouteContext
164
- : TRouteContextReturn,
165
- TAllContext = Assign<
166
- IsAny<TParentRoute['types']['allContext'], {}>,
167
- TRouteContext
168
- >,
169
- TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
89
+ TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>,
90
+ TRouteContextReturn = RouteContext,
91
+ TRouteContext = ResolveRouteContext<TRouteContextReturn>,
92
+ TAllContext = ResolveAllContext<TParentRoute, TRouteContext>,
93
+ TRouterContext = AnyContext,
170
94
  TLoaderDeps extends Record<string, any> = {},
171
95
  TLoaderDataReturn = unknown,
172
- TLoaderData = [TLoaderDataReturn] extends [never]
173
- ? undefined
174
- : TLoaderDataReturn,
175
- TChildren extends RouteConstraints['TChildren'] = unknown,
96
+ TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
97
+ TChildren = unknown,
176
98
  >(
177
99
  options?: FileBaseRouteOptions<
178
100
  TParentRoute,
package/src/index.tsx CHANGED
@@ -28,12 +28,6 @@ export {
28
28
  createLazyRoute,
29
29
  createLazyFileRoute,
30
30
  type FileRoutesByPath,
31
- type Trim,
32
- type TrimLeft,
33
- type TrimRight,
34
- type RemoveUnderScores,
35
- type ResolveFilePath,
36
- type FileRoutePath,
37
31
  type LazyRouteOptions,
38
32
  } from './fileRoute'
39
33
  export * from './history'
@@ -60,7 +54,6 @@ export {
60
54
  type ToMaskOptions,
61
55
  type ToSubOptions,
62
56
  type ResolveRoute,
63
- type ParamOptions,
64
57
  type SearchParamOptions,
65
58
  type PathParamOptions,
66
59
  type ToPathOption,
@@ -162,7 +155,6 @@ export {
162
155
  type ResolveFullSearchSchema,
163
156
  type ResolveFullSearchSchemaInput,
164
157
  type AnyRoute,
165
- type MergeFromFromParent,
166
158
  type ResolveAllParams,
167
159
  type RouteConstraints,
168
160
  type AnyRootRoute,
@@ -258,6 +250,7 @@ export {
258
250
  export { useRouteContext } from './useRouteContext'
259
251
  export { useRouter } from './useRouter'
260
252
  export { useRouterState } from './useRouterState'
253
+ export { useLocation } from './useLocation'
261
254
  export {
262
255
  escapeJSON, // SSR
263
256
  useLayoutEffect, // SSR