@tanstack/react-router 1.35.2 → 1.35.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"useSearch.js","sources":["../../src/useSearch.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { AnyRoute, RootSearchSchema } from './route'\nimport type { FullSearchSchema, RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { MakeRouteMatch } from './Matches'\nimport type { StrictOrFrom } from './utils'\n\nexport type UseSearchOptions<\n TFrom,\n TStrict extends boolean,\n TSearch,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (search: TSearch) => TSelected\n}\n\nexport function useSearch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TSearch = TStrict extends false\n ? FullSearchSchema<TRouteTree>\n : Exclude<\n RouteById<TRouteTree, TFrom>['types']['fullSearchSchema'],\n RootSearchSchema\n >,\n TSelected = TSearch,\n>(opts: UseSearchOptions<TFrom, TStrict, TSearch, TSelected>): TSelected {\n return useMatch({\n ...opts,\n select: (match: MakeRouteMatch<TRouteTree, TFrom>) => {\n return opts.select ? opts.select(match.search) : match.search\n },\n })\n}\n"],"names":[],"mappings":";AAgBO,SAAS,UAWd,MAAuE;AACvE,SAAO,SAAS;AAAA,IACd,GAAG;AAAA,IACH,QAAQ,CAAC,UAA6C;AACpD,aAAO,KAAK,SAAS,KAAK,OAAO,MAAM,MAAM,IAAI,MAAM;AAAA,IACzD;AAAA,EAAA,CACD;AACH;"}
1
+ {"version":3,"file":"useSearch.js","sources":["../../src/useSearch.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { AnyRoute } from './route'\nimport type { FullSearchSchema, RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { MakeRouteMatch } from './Matches'\nimport type { Expand, StrictOrFrom } from './utils'\n\nexport type UseSearchOptions<\n TFrom,\n TStrict extends boolean,\n TSearch,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (search: TSearch) => TSelected\n}\n\nexport function useSearch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TSearch = TStrict extends false\n ? FullSearchSchema<TRouteTree>\n : Expand<RouteById<TRouteTree, TFrom>['types']['fullSearchSchema']>,\n TSelected = TSearch,\n>(opts: UseSearchOptions<TFrom, TStrict, TSearch, TSelected>): TSelected {\n return useMatch({\n ...opts,\n select: (match: MakeRouteMatch<TRouteTree, TFrom>) => {\n return opts.select ? opts.select(match.search) : match.search\n },\n })\n}\n"],"names":[],"mappings":";AAgBO,SAAS,UAQd,MAAuE;AACvE,SAAO,SAAS;AAAA,IACd,GAAG;AAAA,IACH,QAAQ,CAAC,UAA6C;AACpD,aAAO,KAAK,SAAS,KAAK,OAAO,MAAM,MAAM,IAAI,MAAM;AAAA,IACzD;AAAA,EAAA,CACD;AACH;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.35.2",
3
+ "version": "1.35.5",
4
4
  "description": "",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/index.tsx CHANGED
@@ -156,7 +156,6 @@ export {
156
156
  type AnyRoute,
157
157
  type RouteConstraints,
158
158
  type AnyRootRoute,
159
- type RootSearchSchema,
160
159
  type ResolveFullPath,
161
160
  type RouteMask,
162
161
  type ErrorRouteProps,
package/src/link.tsx CHANGED
@@ -7,7 +7,6 @@ import { deepEqual, functionalUpdate } from './utils'
7
7
  import { exactPathTest, removeTrailingSlash } from './path'
8
8
  import type { AnyRouter, ParsedLocation } from '.'
9
9
  import type { HistoryState } from '@tanstack/history'
10
- import type { AnyRoute, RootSearchSchema } from './route'
11
10
  import type {
12
11
  AllParams,
13
12
  CatchAllPaths,
@@ -251,9 +250,6 @@ type ParamsReducer<
251
250
 
252
251
  type ParamVariant = 'PATH' | 'SEARCH'
253
252
 
254
- type ExcludeRootSearchSchema<T> =
255
- Exclude<T, RootSearchSchema> extends never ? {} : Exclude<T, RootSearchSchema>
256
-
257
253
  export type ResolveRoute<
258
254
  TRouter extends AnyRouter,
259
255
  TFrom,
@@ -265,11 +261,6 @@ export type ResolveRoute<
265
261
  : RouteByToPath<TRouter, TPath>
266
262
  : never
267
263
 
268
- type PostProcessParams<
269
- T,
270
- TParamVariant extends ParamVariant,
271
- > = TParamVariant extends 'SEARCH' ? ExcludeRootSearchSchema<T> : T
272
-
273
264
  type ResolveFromParamType<TParamVariant extends ParamVariant> =
274
265
  TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchema'
275
266
 
@@ -312,14 +303,11 @@ export type ResolveToParams<
312
303
  ? ResolveAllToParams<TRouter, TParamVariant>
313
304
  : TPath extends CatchAllPaths
314
305
  ? ResolveAllToParams<TRouter, TParamVariant>
315
- : PostProcessParams<
316
- ResolveRoute<
317
- TRouter,
318
- TFrom,
319
- TTo
320
- >['types'][ResolveToParamType<TParamVariant>],
321
- TParamVariant
322
- >
306
+ : ResolveRoute<
307
+ TRouter,
308
+ TFrom,
309
+ TTo
310
+ >['types'][ResolveToParamType<TParamVariant>]
323
311
  : never
324
312
 
325
313
  type ResolveRelativeToParams<
@@ -598,6 +586,7 @@ export function useLinkProps<
598
586
  // null for LinkUtils
599
587
 
600
588
  const dest = {
589
+ ...(options.to && { from: matchPathname }),
601
590
  ...options,
602
591
  }
603
592
 
package/src/route.ts CHANGED
@@ -56,8 +56,6 @@ export type RouteOptions<
56
56
  TPath extends string = string,
57
57
  TSearchSchemaInput = Record<string, unknown>,
58
58
  TSearchSchema = {},
59
- TSearchSchemaUsed = {},
60
- TFullSearchSchemaInput = TSearchSchemaUsed,
61
59
  TFullSearchSchema = TSearchSchema,
62
60
  TParams = AnyPathParams,
63
61
  TAllParams = TParams,
@@ -74,8 +72,6 @@ export type RouteOptions<
74
72
  TPath,
75
73
  TSearchSchemaInput,
76
74
  TSearchSchema,
77
- TSearchSchemaUsed,
78
- TFullSearchSchemaInput,
79
75
  TFullSearchSchema,
80
76
  TParams,
81
77
  TAllParams,
@@ -170,8 +166,6 @@ export type BaseRouteOptions<
170
166
  TPath extends string = string,
171
167
  TSearchSchemaInput = Record<string, unknown>,
172
168
  TSearchSchema = {},
173
- TSearchSchemaUsed = {},
174
- TFullSearchSchemaInput = TSearchSchemaUsed,
175
169
  TFullSearchSchema = TSearchSchema,
176
170
  TParams = {},
177
171
  TAllParams = ParamsFallback<TPath, TParams>,
@@ -398,28 +392,15 @@ export type ResolveFullSearchSchema<
398
392
  TParentRoute extends AnyRoute,
399
393
  TSearchSchema,
400
394
  > = unknown extends TParentRoute
401
- ? Omit<TSearchSchema, keyof RootSearchSchema>
402
- : Assign<
403
- TParentRoute['id'] extends RootRouteId
404
- ? Omit<TParentRoute['types']['searchSchema'], keyof RootSearchSchema>
405
- : TParentRoute['types']['fullSearchSchema'],
406
- TSearchSchema
407
- >
395
+ ? TSearchSchema
396
+ : Assign<TParentRoute['types']['fullSearchSchema'], TSearchSchema>
408
397
 
409
398
  export type ResolveFullSearchSchemaInput<
410
399
  TParentRoute extends AnyRoute,
411
400
  TSearchSchemaUsed,
412
401
  > = unknown extends TParentRoute
413
- ? Omit<TSearchSchemaUsed, keyof RootSearchSchema>
414
- : Assign<
415
- TParentRoute['id'] extends RootRouteId
416
- ? Omit<
417
- TParentRoute['types']['searchSchemaInput'],
418
- keyof RootSearchSchema
419
- >
420
- : TParentRoute['types']['fullSearchSchemaInput'],
421
- TSearchSchemaUsed
422
- >
402
+ ? TSearchSchemaUsed
403
+ : Assign<TParentRoute['types']['fullSearchSchemaInput'], TSearchSchemaUsed>
423
404
 
424
405
  export type ResolveRouteContext<TRouteContextReturn> = [
425
406
  TRouteContextReturn,
@@ -628,8 +609,6 @@ export class Route<
628
609
  TPath,
629
610
  TSearchSchemaInput,
630
611
  TSearchSchema,
631
- TSearchSchemaUsed,
632
- TFullSearchSchemaInput,
633
612
  TFullSearchSchema,
634
613
  TParams,
635
614
  TAllParams,
@@ -667,8 +646,6 @@ export class Route<
667
646
  TPath,
668
647
  TSearchSchemaInput,
669
648
  TSearchSchema,
670
- TSearchSchemaUsed,
671
- TFullSearchSchemaInput,
672
649
  TFullSearchSchema,
673
650
  TParams,
674
651
  TAllParams,
@@ -723,8 +700,6 @@ export class Route<
723
700
  TPath,
724
701
  TSearchSchemaInput,
725
702
  TSearchSchema,
726
- TSearchSchemaUsed,
727
- TFullSearchSchemaInput,
728
703
  TFullSearchSchema,
729
704
  TParams,
730
705
  TAllParams,
@@ -969,8 +944,6 @@ export function createRoute<
969
944
  TPath,
970
945
  TSearchSchemaInput,
971
946
  TSearchSchema,
972
- TSearchSchemaUsed,
973
- TFullSearchSchemaInput,
974
947
  TFullSearchSchema,
975
948
  TParams,
976
949
  TAllParams,
@@ -1010,9 +983,8 @@ export function createRoute<
1010
983
  export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>
1011
984
 
1012
985
  export type RootRouteOptions<
1013
- TSearchSchemaInput = RootSearchSchema,
1014
- TSearchSchema = RootSearchSchema,
1015
- TSearchSchemaUsed = RootSearchSchema,
986
+ TSearchSchemaInput = {},
987
+ TSearchSchema = {},
1016
988
  TRouteContextReturn = RouteContext,
1017
989
  TRouteContext = ResolveRouteContext<TRouteContextReturn>,
1018
990
  TRouterContext = {},
@@ -1026,8 +998,6 @@ export type RootRouteOptions<
1026
998
  '', // TPath
1027
999
  TSearchSchemaInput, // TSearchSchemaInput
1028
1000
  TSearchSchema, // TSearchSchema
1029
- TSearchSchemaUsed,
1030
- TSearchSchemaUsed, //TFullSearchSchemaInput
1031
1001
  TSearchSchema, // TFullSearchSchema
1032
1002
  {}, // TParams
1033
1003
  {}, // TAllParams
@@ -1049,13 +1019,15 @@ export type RootRouteOptions<
1049
1019
 
1050
1020
  export function createRootRouteWithContext<TRouterContext extends {}>() {
1051
1021
  return <
1052
- TSearchSchemaInput extends Record<string, any> = RootSearchSchema,
1053
- TSearchSchema extends Record<string, any> = RootSearchSchema,
1054
- TSearchSchemaUsed extends Record<string, any> = RootSearchSchema,
1022
+ TSearchSchemaInput = {},
1023
+ TSearchSchema = {},
1024
+ TSearchSchemaUsed = ResolveSearchSchemaUsed<
1025
+ TSearchSchemaInput,
1026
+ TSearchSchema
1027
+ >,
1055
1028
  TRouteContextReturn extends RouteContext = RouteContext,
1056
- TRouteContext extends RouteContext = [TRouteContextReturn] extends [never]
1057
- ? RouteContext
1058
- : TRouteContextReturn,
1029
+ TRouteContext extends
1030
+ RouteContext = ResolveRouteContext<TRouteContextReturn>,
1059
1031
  TLoaderDeps extends Record<string, any> = {},
1060
1032
  TLoaderDataReturn = {},
1061
1033
  TLoaderData = ResolveLoaderData<TLoaderDataReturn>,
@@ -1063,7 +1035,6 @@ export function createRootRouteWithContext<TRouterContext extends {}>() {
1063
1035
  options?: RootRouteOptions<
1064
1036
  TSearchSchemaInput,
1065
1037
  TSearchSchema,
1066
- TSearchSchemaUsed,
1067
1038
  TRouteContextReturn,
1068
1039
  TRouteContext,
1069
1040
  TRouterContext,
@@ -1090,14 +1061,10 @@ export function createRootRouteWithContext<TRouterContext extends {}>() {
1090
1061
  */
1091
1062
  export const rootRouteWithContext = createRootRouteWithContext
1092
1063
 
1093
- export type RootSearchSchema = {
1094
- __TRootSearchSchema__: '__TRootSearchSchema__'
1095
- }
1096
-
1097
1064
  export class RootRoute<
1098
- in out TSearchSchemaInput = RootSearchSchema,
1099
- in out TSearchSchema = RootSearchSchema,
1100
- in out TSearchSchemaUsed = RootSearchSchema,
1065
+ in out TSearchSchemaInput = {},
1066
+ in out TSearchSchema = {},
1067
+ in out TSearchSchemaUsed = {},
1101
1068
  TRouteContextReturn = RouteContext,
1102
1069
  in out TRouteContext = ResolveRouteContext<TRouteContextReturn>,
1103
1070
  in out TRouterContext = {},
@@ -1133,7 +1100,6 @@ export class RootRoute<
1133
1100
  options?: RootRouteOptions<
1134
1101
  TSearchSchemaInput,
1135
1102
  TSearchSchema,
1136
- TSearchSchemaUsed,
1137
1103
  TRouteContextReturn,
1138
1104
  TRouteContext,
1139
1105
  TRouterContext,
@@ -1147,9 +1113,12 @@ export class RootRoute<
1147
1113
  }
1148
1114
 
1149
1115
  export function createRootRoute<
1150
- TSearchSchemaInput = RootSearchSchema,
1151
- TSearchSchema = RootSearchSchema,
1152
- TSearchSchemaUsed = RootSearchSchema,
1116
+ TSearchSchemaInput = {},
1117
+ TSearchSchema = {},
1118
+ TSearchSchemaUsed = ResolveSearchSchemaUsed<
1119
+ TSearchSchemaInput,
1120
+ TSearchSchema
1121
+ >,
1153
1122
  TRouteContextReturn = RouteContext,
1154
1123
  TRouteContext = ResolveRouteContext<TRouteContextReturn>,
1155
1124
  TRouterContext = {},
@@ -1164,9 +1133,7 @@ export function createRootRoute<
1164
1133
  '', // TPath
1165
1134
  TSearchSchemaInput, // TSearchSchemaInput
1166
1135
  TSearchSchema, // TSearchSchema
1167
- TSearchSchemaUsed,
1168
- TSearchSchemaUsed, // TFullSearchSchemaInput
1169
- TSearchSchema, // TFullSearchSchema
1136
+ TSearchSchema,
1170
1137
  {}, // TParams
1171
1138
  {}, // TAllParams
1172
1139
  TRouteContextReturn, // TRouteContextReturn
@@ -1306,10 +1273,7 @@ export class NotFoundRoute<
1306
1273
  TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
1307
1274
  TRouteContextReturn = AnyContext,
1308
1275
  TRouteContext = RouteContext,
1309
- TAllContext = Assign<
1310
- IsAny<TParentRoute['types']['allContext'], {}>,
1311
- TRouteContext
1312
- >,
1276
+ TAllContext = ResolveAllContext<TParentRoute, TRouteContext>,
1313
1277
  TRouterContext = AnyContext,
1314
1278
  TLoaderDeps extends Record<string, any> = {},
1315
1279
  TLoaderDataReturn = {},
@@ -1345,8 +1309,6 @@ export class NotFoundRoute<
1345
1309
  string,
1346
1310
  TSearchSchemaInput,
1347
1311
  TSearchSchema,
1348
- TSearchSchemaUsed,
1349
- TFullSearchSchemaInput,
1350
1312
  TFullSearchSchema,
1351
1313
  {},
1352
1314
  {},
package/src/routeInfo.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyRoute, RootSearchSchema } from './route'
1
+ import type { AnyRoute } from './route'
2
2
  import type { AnyRouter, TrailingSlashOption } from './router'
3
3
  import type { Expand, MergeUnion } from './utils'
4
4
 
@@ -115,14 +115,11 @@ export type RouteByToPath<TRouter extends AnyRouter, TTo> = Extract<
115
115
  >
116
116
 
117
117
  export type FullSearchSchema<TRouteTree extends AnyRoute> = MergeUnion<
118
- Exclude<ParseRoute<TRouteTree>['types']['fullSearchSchema'], RootSearchSchema>
118
+ ParseRoute<TRouteTree>['types']['fullSearchSchema']
119
119
  >
120
120
 
121
121
  export type FullSearchSchemaInput<TRouteTree extends AnyRoute> = MergeUnion<
122
- Exclude<
123
- ParseRoute<TRouteTree>['types']['fullSearchSchemaInput'],
124
- RootSearchSchema
125
- >
122
+ ParseRoute<TRouteTree>['types']['fullSearchSchemaInput']
126
123
  >
127
124
 
128
125
  export type AllParams<TRouteTree extends AnyRoute> = MergeUnion<
package/src/router.ts CHANGED
@@ -1102,27 +1102,14 @@ export class Router<
1102
1102
  ): ParsedLocation => {
1103
1103
  let fromPath = this.latestLocation.pathname
1104
1104
  let fromSearch = dest.fromSearch || this.latestLocation.search
1105
- const looseRoutesByPath = this.routesByPath as Record<string, AnyRoute>
1106
-
1107
- const fromRoute =
1108
- dest.from !== undefined
1109
- ? looseRoutesByPath[trimPathRight(dest.from)]
1110
- : undefined
1111
1105
 
1112
1106
  const fromMatches = this.matchRoutes(
1113
1107
  this.latestLocation.pathname,
1114
1108
  fromSearch,
1115
1109
  )
1116
1110
 
1117
- const fromMatch = fromMatches.find((d) => d.routeId === fromRoute?.id)
1118
-
1119
- fromPath = fromMatch?.pathname || fromPath
1120
-
1121
- invariant(
1122
- dest.from == null || fromMatch != null,
1123
- 'Could not find match for from: ' + dest.from,
1124
- )
1125
-
1111
+ fromPath =
1112
+ fromMatches.find((d) => d.id === dest.from)?.pathname || fromPath
1126
1113
  fromSearch = last(fromMatches)?.search || this.latestLocation.search
1127
1114
 
1128
1115
  const stayingMatches = matches?.filter((d) =>
@@ -1786,7 +1773,8 @@ export class Router<
1786
1773
  preload: !!preload,
1787
1774
  context: parentContext,
1788
1775
  location,
1789
- navigate: (opts: any) => this.navigate({ ...opts }),
1776
+ navigate: (opts: any) =>
1777
+ this.navigate({ ...opts, from: match.pathname }),
1790
1778
  buildLocation: this.buildLocation,
1791
1779
  cause: preload ? 'preload' : match.cause,
1792
1780
  })) ?? ({} as any)
@@ -1839,7 +1827,8 @@ export class Router<
1839
1827
  abortController: match.abortController,
1840
1828
  context: match.context,
1841
1829
  location,
1842
- navigate: (opts) => this.navigate({ ...opts } as any),
1830
+ navigate: (opts) =>
1831
+ this.navigate({ ...opts, from: match.pathname } as any),
1843
1832
  cause: preload ? 'preload' : match.cause,
1844
1833
  route,
1845
1834
  }
@@ -29,6 +29,7 @@ export function useNavigate<
29
29
  (options: NavigateOptions) => {
30
30
  return router.navigate({
31
31
  ...options,
32
+ from: options.to ? router.state.resolvedLocation.pathname : undefined,
32
33
  })
33
34
  },
34
35
  [router],
@@ -62,6 +63,7 @@ export function Navigate<
62
63
 
63
64
  React.useEffect(() => {
64
65
  navigate({
66
+ from: props.to ? match.pathname : undefined,
65
67
  ...props,
66
68
  } as any)
67
69
  // eslint-disable-next-line react-hooks/exhaustive-deps
package/src/useSearch.tsx CHANGED
@@ -1,9 +1,9 @@
1
1
  import { useMatch } from './useMatch'
2
- import type { AnyRoute, RootSearchSchema } from './route'
2
+ import type { AnyRoute } from './route'
3
3
  import type { FullSearchSchema, RouteById, RouteIds } from './routeInfo'
4
4
  import type { RegisteredRouter } from './router'
5
5
  import type { MakeRouteMatch } from './Matches'
6
- import type { StrictOrFrom } from './utils'
6
+ import type { Expand, StrictOrFrom } from './utils'
7
7
 
8
8
  export type UseSearchOptions<
9
9
  TFrom,
@@ -20,10 +20,7 @@ export function useSearch<
20
20
  TStrict extends boolean = true,
21
21
  TSearch = TStrict extends false
22
22
  ? FullSearchSchema<TRouteTree>
23
- : Exclude<
24
- RouteById<TRouteTree, TFrom>['types']['fullSearchSchema'],
25
- RootSearchSchema
26
- >,
23
+ : Expand<RouteById<TRouteTree, TFrom>['types']['fullSearchSchema']>,
27
24
  TSelected = TSearch,
28
25
  >(opts: UseSearchOptions<TFrom, TStrict, TSearch, TSelected>): TSelected {
29
26
  return useMatch({