@tanstack/react-router 1.4.8 → 1.4.10
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/build/cjs/Matches.js.map +1 -1
- package/build/cjs/link.js.map +1 -1
- package/build/cjs/route.js +1 -2
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/useNavigate.js +1 -2
- package/build/cjs/useNavigate.js.map +1 -1
- package/build/cjs/useParams.js.map +1 -1
- package/build/cjs/useSearch.js.map +1 -1
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +2 -4
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +355 -355
- package/build/types/Matches.d.ts +9 -9
- package/build/types/link.d.ts +6 -6
- package/build/types/useNavigate.d.ts +3 -2
- package/build/types/useParams.d.ts +3 -3
- package/build/types/useSearch.d.ts +3 -3
- package/build/types/utils.d.ts +4 -3
- package/build/umd/index.development.js +2 -4
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/Matches.tsx +10 -12
- package/src/link.tsx +6 -5
- package/src/route.ts +12 -13
- package/src/useNavigate.tsx +4 -3
- package/src/useParams.tsx +4 -5
- package/src/useSearch.tsx +4 -5
- package/src/utils.ts +8 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.10",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@tanstack/store": "^0.1.3",
|
|
45
45
|
"tiny-invariant": "^1.3.1",
|
|
46
46
|
"tiny-warning": "^1.0.3",
|
|
47
|
-
"@tanstack/history": "1.4.
|
|
47
|
+
"@tanstack/history": "1.4.10"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "rollup --config rollup.config.js"
|
package/src/Matches.tsx
CHANGED
|
@@ -4,9 +4,8 @@ import warning from 'tiny-warning'
|
|
|
4
4
|
import { CatchBoundary, ErrorComponent } from './CatchBoundary'
|
|
5
5
|
import { useRouter, useRouterState } from './RouterProvider'
|
|
6
6
|
import { ResolveRelativePath, ToOptions } from './link'
|
|
7
|
-
import { AnyRoute, ReactNode,
|
|
7
|
+
import { AnyRoute, ReactNode, RootSearchSchema } from './route'
|
|
8
8
|
import {
|
|
9
|
-
FullSearchSchema,
|
|
10
9
|
ParseRoute,
|
|
11
10
|
RouteById,
|
|
12
11
|
RouteByPath,
|
|
@@ -37,8 +36,10 @@ export interface RouteMatch<
|
|
|
37
36
|
loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData']
|
|
38
37
|
routeContext: RouteById<TRouteTree, TRouteId>['types']['routeContext']
|
|
39
38
|
context: RouteById<TRouteTree, TRouteId>['types']['allContext']
|
|
40
|
-
search:
|
|
41
|
-
RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema']
|
|
39
|
+
search: Exclude<
|
|
40
|
+
RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'],
|
|
41
|
+
RootSearchSchema
|
|
42
|
+
>
|
|
42
43
|
fetchCount: number
|
|
43
44
|
abortController: AbortController
|
|
44
45
|
cause: 'preload' | 'enter' | 'stay'
|
|
@@ -295,14 +296,13 @@ export function getRenderedMatches(state: RouterState) {
|
|
|
295
296
|
export function useMatch<
|
|
296
297
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
297
298
|
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|
|
298
|
-
TStrict extends boolean = true,
|
|
299
299
|
TRouteMatchState = RouteMatch<TRouteTree, TFrom>,
|
|
300
300
|
TSelected = TRouteMatchState,
|
|
301
301
|
>(
|
|
302
302
|
opts: StrictOrFrom<TFrom> & {
|
|
303
303
|
select?: (match: TRouteMatchState) => TSelected
|
|
304
304
|
},
|
|
305
|
-
):
|
|
305
|
+
): TSelected {
|
|
306
306
|
const router = useRouter()
|
|
307
307
|
const nearestMatchId = React.useContext(matchContext)
|
|
308
308
|
|
|
@@ -380,7 +380,6 @@ export function useParentMatches<T = RouteMatch[]>(opts?: {
|
|
|
380
380
|
export function useLoaderDeps<
|
|
381
381
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
382
382
|
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|
|
383
|
-
TStrict extends boolean = true,
|
|
384
383
|
TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<
|
|
385
384
|
TRouteTree,
|
|
386
385
|
TFrom
|
|
@@ -390,7 +389,7 @@ export function useLoaderDeps<
|
|
|
390
389
|
opts: StrictOrFrom<TFrom> & {
|
|
391
390
|
select?: (match: TRouteMatch) => TSelected
|
|
392
391
|
},
|
|
393
|
-
):
|
|
392
|
+
): TSelected {
|
|
394
393
|
return useMatch({
|
|
395
394
|
...opts,
|
|
396
395
|
select: (s) => {
|
|
@@ -398,13 +397,12 @@ export function useLoaderDeps<
|
|
|
398
397
|
? opts.select(s?.loaderDeps)
|
|
399
398
|
: s?.loaderDeps
|
|
400
399
|
},
|
|
401
|
-
})
|
|
400
|
+
})
|
|
402
401
|
}
|
|
403
402
|
|
|
404
403
|
export function useLoaderData<
|
|
405
404
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
406
405
|
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|
|
407
|
-
TStrict extends boolean = true,
|
|
408
406
|
TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<
|
|
409
407
|
TRouteTree,
|
|
410
408
|
TFrom
|
|
@@ -414,7 +412,7 @@ export function useLoaderData<
|
|
|
414
412
|
opts: StrictOrFrom<TFrom> & {
|
|
415
413
|
select?: (match: TRouteMatch) => TSelected
|
|
416
414
|
},
|
|
417
|
-
):
|
|
415
|
+
): TSelected {
|
|
418
416
|
return useMatch({
|
|
419
417
|
...opts,
|
|
420
418
|
select: (s) => {
|
|
@@ -422,5 +420,5 @@ export function useLoaderData<
|
|
|
422
420
|
? opts.select(s?.loaderData)
|
|
423
421
|
: s?.loaderData
|
|
424
422
|
},
|
|
425
|
-
})
|
|
423
|
+
})
|
|
426
424
|
}
|
package/src/link.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
NoInfer,
|
|
16
16
|
NonNullableUpdater,
|
|
17
17
|
PickRequired,
|
|
18
|
+
StringLiteral,
|
|
18
19
|
Updater,
|
|
19
20
|
WithoutEmpty,
|
|
20
21
|
deepEqual,
|
|
@@ -114,7 +115,7 @@ export type RelativeToPathAutoComplete<
|
|
|
114
115
|
|
|
115
116
|
export type NavigateOptions<
|
|
116
117
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
117
|
-
TFrom extends RoutePaths<TRouteTree> | string =
|
|
118
|
+
TFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>,
|
|
118
119
|
TTo extends string = '',
|
|
119
120
|
TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,
|
|
120
121
|
TMaskTo extends string = '',
|
|
@@ -128,7 +129,7 @@ export type NavigateOptions<
|
|
|
128
129
|
|
|
129
130
|
export type ToOptions<
|
|
130
131
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
131
|
-
TFrom extends RoutePaths<TRouteTree> | string =
|
|
132
|
+
TFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>,
|
|
132
133
|
TTo extends string = '',
|
|
133
134
|
TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,
|
|
134
135
|
TMaskTo extends string = '',
|
|
@@ -138,7 +139,7 @@ export type ToOptions<
|
|
|
138
139
|
|
|
139
140
|
export type ToMaskOptions<
|
|
140
141
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
141
|
-
TMaskFrom extends RoutePaths<TRouteTree> | string =
|
|
142
|
+
TMaskFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>,
|
|
142
143
|
TMaskTo extends string = '',
|
|
143
144
|
> = ToSubOptions<TRouteTree, TMaskFrom, TMaskTo> & {
|
|
144
145
|
unmaskOnReload?: boolean
|
|
@@ -146,7 +147,7 @@ export type ToMaskOptions<
|
|
|
146
147
|
|
|
147
148
|
export type ToSubOptions<
|
|
148
149
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
149
|
-
TFrom extends RoutePaths<TRouteTree> | string =
|
|
150
|
+
TFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>,
|
|
150
151
|
TTo extends string = '',
|
|
151
152
|
TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,
|
|
152
153
|
> = {
|
|
@@ -156,7 +157,7 @@ export type ToSubOptions<
|
|
|
156
157
|
// State to pass to the history stack
|
|
157
158
|
state?: true | NonNullableUpdater<HistoryState>
|
|
158
159
|
// The source route path. This is automatically set when using route-level APIs, but for type-safe relative routing on the router itself, this is required
|
|
159
|
-
from?: TFrom
|
|
160
|
+
from?: StringLiteral<TFrom>
|
|
160
161
|
// // When using relative route paths, this option forces resolution from the current path, instead of the route API's path or `from` path
|
|
161
162
|
} & CheckPath<TRouteTree, NoInfer<TResolved>, {}> &
|
|
162
163
|
SearchParamOptions<TRouteTree, TFrom, TTo, TResolved> &
|
package/src/route.ts
CHANGED
|
@@ -485,41 +485,40 @@ export class RouteApi<
|
|
|
485
485
|
useMatch = <TSelected = TAllContext>(opts?: {
|
|
486
486
|
select?: (s: TAllContext) => TSelected
|
|
487
487
|
}): TSelected => {
|
|
488
|
-
return useMatch({
|
|
488
|
+
return useMatch({ select: opts?.select, from: this.id })
|
|
489
489
|
}
|
|
490
490
|
|
|
491
491
|
useRouteContext = <TSelected = TAllContext>(opts?: {
|
|
492
492
|
select?: (s: TAllContext) => TSelected
|
|
493
493
|
}): TSelected => {
|
|
494
494
|
return useMatch({
|
|
495
|
-
...opts,
|
|
496
495
|
from: this.id,
|
|
497
496
|
select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),
|
|
498
|
-
}
|
|
497
|
+
})
|
|
499
498
|
}
|
|
500
499
|
|
|
501
500
|
useSearch = <TSelected = TFullSearchSchema>(opts?: {
|
|
502
501
|
select?: (s: TFullSearchSchema) => TSelected
|
|
503
502
|
}): TSelected => {
|
|
504
|
-
return useSearch({ ...opts, from: this.id }
|
|
503
|
+
return useSearch({ ...opts, from: this.id })
|
|
505
504
|
}
|
|
506
505
|
|
|
507
506
|
useParams = <TSelected = TAllParams>(opts?: {
|
|
508
507
|
select?: (s: TAllParams) => TSelected
|
|
509
508
|
}): TSelected => {
|
|
510
|
-
return useParams({ ...opts, from: this.id }
|
|
509
|
+
return useParams({ ...opts, from: this.id })
|
|
511
510
|
}
|
|
512
511
|
|
|
513
512
|
useLoaderDeps = <TSelected = TLoaderDeps>(opts?: {
|
|
514
513
|
select?: (s: TLoaderDeps) => TSelected
|
|
515
514
|
}): TSelected => {
|
|
516
|
-
return useLoaderDeps({ ...opts, from: this.id } as any)
|
|
515
|
+
return useLoaderDeps({ ...opts, from: this.id } as any)
|
|
517
516
|
}
|
|
518
517
|
|
|
519
518
|
useLoaderData = <TSelected = TLoaderData>(opts?: {
|
|
520
519
|
select?: (s: TLoaderData) => TSelected
|
|
521
520
|
}): TSelected => {
|
|
522
|
-
return useLoaderData({ ...opts, from: this.id } as any)
|
|
521
|
+
return useLoaderData({ ...opts, from: this.id } as any)
|
|
523
522
|
}
|
|
524
523
|
}
|
|
525
524
|
|
|
@@ -810,7 +809,7 @@ export class Route<
|
|
|
810
809
|
useMatch = <TSelected = TAllContext>(opts?: {
|
|
811
810
|
select?: (search: TAllContext) => TSelected
|
|
812
811
|
}): TSelected => {
|
|
813
|
-
return useMatch({ ...opts, from: this.id })
|
|
812
|
+
return useMatch({ ...opts, from: this.id })
|
|
814
813
|
}
|
|
815
814
|
|
|
816
815
|
useRouteContext = <TSelected = TAllContext>(opts?: {
|
|
@@ -820,31 +819,31 @@ export class Route<
|
|
|
820
819
|
...opts,
|
|
821
820
|
from: this.id,
|
|
822
821
|
select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),
|
|
823
|
-
}
|
|
822
|
+
})
|
|
824
823
|
}
|
|
825
824
|
|
|
826
825
|
useSearch = <TSelected = TFullSearchSchema>(opts?: {
|
|
827
826
|
select?: (search: TFullSearchSchema) => TSelected
|
|
828
827
|
}): TSelected => {
|
|
829
|
-
return useSearch({ ...opts, from: this.id }
|
|
828
|
+
return useSearch({ ...opts, from: this.id })
|
|
830
829
|
}
|
|
831
830
|
|
|
832
831
|
useParams = <TSelected = TAllParams>(opts?: {
|
|
833
832
|
select?: (search: TAllParams) => TSelected
|
|
834
833
|
}): TSelected => {
|
|
835
|
-
return useParams({ ...opts, from: this.id }
|
|
834
|
+
return useParams({ ...opts, from: this.id })
|
|
836
835
|
}
|
|
837
836
|
|
|
838
837
|
useLoaderDeps = <TSelected = TLoaderDeps>(opts?: {
|
|
839
838
|
select?: (s: TLoaderDeps) => TSelected
|
|
840
839
|
}): TSelected => {
|
|
841
|
-
return useLoaderDeps({ ...opts, from: this.id } as any)
|
|
840
|
+
return useLoaderDeps({ ...opts, from: this.id } as any)
|
|
842
841
|
}
|
|
843
842
|
|
|
844
843
|
useLoaderData = <TSelected = TLoaderData>(opts?: {
|
|
845
844
|
select?: (search: TLoaderData) => TSelected
|
|
846
845
|
}): TSelected => {
|
|
847
|
-
return useLoaderData({ ...opts, from: this.id } as any)
|
|
846
|
+
return useLoaderData({ ...opts, from: this.id } as any)
|
|
848
847
|
}
|
|
849
848
|
}
|
|
850
849
|
|
package/src/useNavigate.tsx
CHANGED
|
@@ -5,12 +5,13 @@ import { LinkOptions, NavigateOptions } from './link'
|
|
|
5
5
|
import { AnyRoute } from './route'
|
|
6
6
|
import { RoutePaths } from './routeInfo'
|
|
7
7
|
import { RegisteredRouter } from './router'
|
|
8
|
+
import { StringLiteral } from './utils'
|
|
8
9
|
|
|
9
10
|
export function useNavigate<
|
|
10
11
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
11
|
-
TDefaultFrom extends RoutePaths<TRouteTree> | string =
|
|
12
|
-
>(_defaultOpts?: { from?: TDefaultFrom }) {
|
|
13
|
-
const { navigate
|
|
12
|
+
TDefaultFrom extends RoutePaths<TRouteTree> | string = RoutePaths<TRouteTree>,
|
|
13
|
+
>(_defaultOpts?: { from?: StringLiteral<TDefaultFrom> }) {
|
|
14
|
+
const { navigate } = useRouter()
|
|
14
15
|
|
|
15
16
|
const matchPathname = useMatch({
|
|
16
17
|
strict: false,
|
package/src/useParams.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyRoute } from './route'
|
|
2
|
-
import { RouteIds, RouteById
|
|
2
|
+
import { RouteIds, RouteById } from './routeInfo'
|
|
3
3
|
import { RegisteredRouter } from './router'
|
|
4
4
|
import { last } from './utils'
|
|
5
5
|
import { useRouterState } from './RouterProvider'
|
|
@@ -9,12 +9,11 @@ import { getRenderedMatches } from './Matches'
|
|
|
9
9
|
export function useParams<
|
|
10
10
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
11
11
|
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
TSelected = TDefaultSelected,
|
|
12
|
+
TParams = RouteById<TRouteTree, TFrom>['types']['allParams'],
|
|
13
|
+
TSelected = TParams,
|
|
15
14
|
>(
|
|
16
15
|
opts: StrictOrFrom<TFrom> & {
|
|
17
|
-
select?: (
|
|
16
|
+
select?: (params: TParams) => TSelected
|
|
18
17
|
},
|
|
19
18
|
): TSelected {
|
|
20
19
|
return useRouterState({
|
package/src/useSearch.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyRoute } from './route'
|
|
1
|
+
import { AnyRoute, RootSearchSchema } from './route'
|
|
2
2
|
import { RouteIds, RouteById } from './routeInfo'
|
|
3
3
|
import { RegisteredRouter } from './router'
|
|
4
4
|
import { RouteMatch } from './Matches'
|
|
@@ -8,16 +8,15 @@ import { StrictOrFrom } from './utils'
|
|
|
8
8
|
export function useSearch<
|
|
9
9
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
10
10
|
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|
|
11
|
-
|
|
12
|
-
TSearch = RouteById<TRouteTree, TFrom>['types']['fullSearchSchema'],
|
|
11
|
+
TSearch = Exclude<RouteById<TRouteTree, TFrom>['types']['fullSearchSchema'], RootSearchSchema>,
|
|
13
12
|
TSelected = TSearch,
|
|
14
13
|
>(
|
|
15
14
|
opts: StrictOrFrom<TFrom> & {
|
|
16
15
|
select?: (search: TSearch) => TSelected
|
|
17
16
|
},
|
|
18
|
-
)
|
|
17
|
+
) : TSelected {
|
|
19
18
|
return useMatch({
|
|
20
|
-
...
|
|
19
|
+
...opts,
|
|
21
20
|
select: (match: RouteMatch) => {
|
|
22
21
|
return opts?.select ? opts.select(match.search as TSearch) : match.search
|
|
23
22
|
},
|
package/src/utils.ts
CHANGED
|
@@ -290,9 +290,15 @@ export function shallow<T>(objA: T, objB: T) {
|
|
|
290
290
|
return true
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
+
export type StringLiteral<T> = T extends string
|
|
294
|
+
? string extends T
|
|
295
|
+
? string
|
|
296
|
+
: T
|
|
297
|
+
: never
|
|
298
|
+
|
|
293
299
|
export type StrictOrFrom<TFrom> =
|
|
294
300
|
| {
|
|
295
|
-
from: TFrom
|
|
301
|
+
from: StringLiteral<TFrom> | TFrom
|
|
296
302
|
strict?: true
|
|
297
303
|
}
|
|
298
304
|
| {
|
|
@@ -303,14 +309,13 @@ export type StrictOrFrom<TFrom> =
|
|
|
303
309
|
export function useRouteContext<
|
|
304
310
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
305
311
|
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|
|
306
|
-
TStrict extends boolean = true,
|
|
307
312
|
TRouteContext = RouteById<TRouteTree, TFrom>['types']['allContext'],
|
|
308
313
|
TSelected = TRouteContext,
|
|
309
314
|
>(
|
|
310
315
|
opts: StrictOrFrom<TFrom> & {
|
|
311
316
|
select?: (search: TRouteContext) => TSelected
|
|
312
317
|
},
|
|
313
|
-
):
|
|
318
|
+
): TSelected {
|
|
314
319
|
return useMatch({
|
|
315
320
|
...(opts as any),
|
|
316
321
|
select: (match: RouteMatch) =>
|