@tanstack/react-router 1.35.3 → 1.35.6
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/index.d.cts +1 -1
- package/dist/cjs/link.cjs +3 -7
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +1 -4
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +15 -21
- package/dist/cjs/routeInfo.d.cts +3 -3
- package/dist/cjs/router.cjs +25 -16
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +1 -0
- package/dist/cjs/useNavigate.cjs +2 -4
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useSearch.cjs.map +1 -1
- package/dist/cjs/useSearch.d.cts +3 -3
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/link.d.ts +1 -4
- package/dist/esm/link.js +3 -7
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/route.d.ts +15 -21
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/routeInfo.d.ts +3 -3
- package/dist/esm/router.d.ts +1 -0
- package/dist/esm/router.js +25 -16
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/useNavigate.js +2 -4
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useSearch.d.ts +3 -3
- package/dist/esm/useSearch.js.map +1 -1
- package/package.json +1 -1
- package/src/index.tsx +0 -1
- package/src/link.tsx +7 -24
- package/src/route.ts +25 -63
- package/src/routeInfo.ts +3 -6
- package/src/router.ts +28 -12
- package/src/useNavigate.tsx +0 -2
- package/src/useSearch.tsx +3 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSearch.js","sources":["../../src/useSearch.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { AnyRoute
|
|
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
package/src/index.tsx
CHANGED
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
|
-
:
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
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<
|
|
@@ -597,11 +585,6 @@ export function useLinkProps<
|
|
|
597
585
|
// If this `to` is a valid external URL, return
|
|
598
586
|
// null for LinkUtils
|
|
599
587
|
|
|
600
|
-
const dest = {
|
|
601
|
-
...(options.to && { from: matchPathname }),
|
|
602
|
-
...options,
|
|
603
|
-
}
|
|
604
|
-
|
|
605
588
|
let type: 'internal' | 'external' = 'internal'
|
|
606
589
|
|
|
607
590
|
try {
|
|
@@ -609,7 +592,7 @@ export function useLinkProps<
|
|
|
609
592
|
type = 'external'
|
|
610
593
|
} catch {}
|
|
611
594
|
|
|
612
|
-
const next = router.buildLocation(
|
|
595
|
+
const next = router.buildLocation(options as any)
|
|
613
596
|
const preload = userPreload ?? router.options.defaultPreload
|
|
614
597
|
const preloadDelay =
|
|
615
598
|
userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0
|
|
@@ -695,7 +678,7 @@ export function useLinkProps<
|
|
|
695
678
|
}
|
|
696
679
|
|
|
697
680
|
const doPreload = () => {
|
|
698
|
-
router.preloadRoute(
|
|
681
|
+
router.preloadRoute(options as any).catch((err) => {
|
|
699
682
|
console.warn(err)
|
|
700
683
|
console.warn(preloadWarning)
|
|
701
684
|
})
|
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
|
-
?
|
|
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
|
-
?
|
|
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 =
|
|
1014
|
-
TSearchSchema =
|
|
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
|
|
1053
|
-
TSearchSchema
|
|
1054
|
-
TSearchSchemaUsed
|
|
1022
|
+
TSearchSchemaInput = {},
|
|
1023
|
+
TSearchSchema = {},
|
|
1024
|
+
TSearchSchemaUsed = ResolveSearchSchemaUsed<
|
|
1025
|
+
TSearchSchemaInput,
|
|
1026
|
+
TSearchSchema
|
|
1027
|
+
>,
|
|
1055
1028
|
TRouteContextReturn extends RouteContext = RouteContext,
|
|
1056
|
-
TRouteContext extends
|
|
1057
|
-
|
|
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 =
|
|
1099
|
-
in out TSearchSchema =
|
|
1100
|
-
in out TSearchSchemaUsed =
|
|
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 =
|
|
1151
|
-
TSearchSchema =
|
|
1152
|
-
TSearchSchemaUsed =
|
|
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
|
-
|
|
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 =
|
|
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
|
|
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
|
-
|
|
118
|
+
ParseRoute<TRouteTree>['types']['fullSearchSchema']
|
|
119
119
|
>
|
|
120
120
|
|
|
121
121
|
export type FullSearchSchemaInput<TRouteTree extends AnyRoute> = MergeUnion<
|
|
122
|
-
|
|
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
|
@@ -380,6 +380,7 @@ export interface BuildNextOptions {
|
|
|
380
380
|
}
|
|
381
381
|
from?: string
|
|
382
382
|
fromSearch?: unknown
|
|
383
|
+
_fromLocation?: ParsedLocation
|
|
383
384
|
}
|
|
384
385
|
|
|
385
386
|
export interface DehydratedRouterState {
|
|
@@ -1100,16 +1101,31 @@ export class Router<
|
|
|
1100
1101
|
} = {},
|
|
1101
1102
|
matches?: Array<MakeRouteMatch<TRouteTree>>,
|
|
1102
1103
|
): ParsedLocation => {
|
|
1103
|
-
|
|
1104
|
-
|
|
1104
|
+
const latestLocation =
|
|
1105
|
+
dest._fromLocation ?? (this.latestLocation as ParsedLocation)
|
|
1106
|
+
let fromPath = latestLocation.pathname
|
|
1107
|
+
let fromSearch = dest.fromSearch || latestLocation.search
|
|
1108
|
+
|
|
1109
|
+
const fromMatches = this.matchRoutes(latestLocation.pathname, fromSearch)
|
|
1110
|
+
|
|
1111
|
+
const fromMatch =
|
|
1112
|
+
dest.from != null
|
|
1113
|
+
? fromMatches.find((d) =>
|
|
1114
|
+
matchPathname(this.basepath, trimPathRight(d.pathname), {
|
|
1115
|
+
to: dest.from,
|
|
1116
|
+
caseSensitive: false,
|
|
1117
|
+
fuzzy: false,
|
|
1118
|
+
}),
|
|
1119
|
+
)
|
|
1120
|
+
: undefined
|
|
1121
|
+
|
|
1122
|
+
fromPath = fromMatch?.pathname || fromPath
|
|
1105
1123
|
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1124
|
+
invariant(
|
|
1125
|
+
dest.from == null || fromMatch != null,
|
|
1126
|
+
'Could not find match for from: ' + dest.from,
|
|
1109
1127
|
)
|
|
1110
1128
|
|
|
1111
|
-
fromPath =
|
|
1112
|
-
fromMatches.find((d) => d.id === dest.from)?.pathname || fromPath
|
|
1113
1129
|
fromSearch = last(fromMatches)?.search || this.latestLocation.search
|
|
1114
1130
|
|
|
1115
1131
|
const stayingMatches = matches?.filter((d) =>
|
|
@@ -1260,9 +1276,10 @@ export class Router<
|
|
|
1260
1276
|
})
|
|
1261
1277
|
|
|
1262
1278
|
if (foundMask) {
|
|
1279
|
+
const { from, ...maskProps } = foundMask
|
|
1263
1280
|
maskedDest = {
|
|
1264
1281
|
...pick(opts, ['from']),
|
|
1265
|
-
...
|
|
1282
|
+
...maskProps,
|
|
1266
1283
|
params,
|
|
1267
1284
|
}
|
|
1268
1285
|
maskedNext = build(maskedDest)
|
|
@@ -1774,7 +1791,7 @@ export class Router<
|
|
|
1774
1791
|
context: parentContext,
|
|
1775
1792
|
location,
|
|
1776
1793
|
navigate: (opts: any) =>
|
|
1777
|
-
this.navigate({ ...opts,
|
|
1794
|
+
this.navigate({ ...opts, _fromLocation: location }),
|
|
1778
1795
|
buildLocation: this.buildLocation,
|
|
1779
1796
|
cause: preload ? 'preload' : match.cause,
|
|
1780
1797
|
})) ?? ({} as any)
|
|
@@ -1828,7 +1845,7 @@ export class Router<
|
|
|
1828
1845
|
context: match.context,
|
|
1829
1846
|
location,
|
|
1830
1847
|
navigate: (opts) =>
|
|
1831
|
-
this.navigate({ ...opts,
|
|
1848
|
+
this.navigate({ ...opts, _fromLocation: location }),
|
|
1832
1849
|
cause: preload ? 'preload' : match.cause,
|
|
1833
1850
|
route,
|
|
1834
1851
|
}
|
|
@@ -2183,9 +2200,8 @@ export class Router<
|
|
|
2183
2200
|
} catch (err) {
|
|
2184
2201
|
if (isRedirect(err)) {
|
|
2185
2202
|
return await this.preloadRoute({
|
|
2186
|
-
fromSearch: next.search,
|
|
2187
|
-
from: next.pathname,
|
|
2188
2203
|
...(err as any),
|
|
2204
|
+
_fromLocation: next,
|
|
2189
2205
|
})
|
|
2190
2206
|
}
|
|
2191
2207
|
// Preload errors are not fatal, but we should still log them
|
package/src/useNavigate.tsx
CHANGED
|
@@ -29,7 +29,6 @@ export function useNavigate<
|
|
|
29
29
|
(options: NavigateOptions) => {
|
|
30
30
|
return router.navigate({
|
|
31
31
|
...options,
|
|
32
|
-
from: options.to ? router.state.resolvedLocation.pathname : undefined,
|
|
33
32
|
})
|
|
34
33
|
},
|
|
35
34
|
[router],
|
|
@@ -63,7 +62,6 @@ export function Navigate<
|
|
|
63
62
|
|
|
64
63
|
React.useEffect(() => {
|
|
65
64
|
navigate({
|
|
66
|
-
from: props.to ? match.pathname : undefined,
|
|
67
65
|
...props,
|
|
68
66
|
} as any)
|
|
69
67
|
// 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
|
|
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
|
-
:
|
|
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({
|