@tanstack/react-router 1.99.9 → 1.100.0

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/src/useParams.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  import { useMatch } from './useMatch'
2
+ import type { ThrowConstraint } from './useMatch'
2
3
  import type {
3
4
  StructuralSharingOption,
4
5
  ValidateSelected,
@@ -6,28 +7,38 @@ import type {
6
7
  import type { AllParams, RouteById } from './routeInfo'
7
8
  import type { AnyRouter, RegisteredRouter } from './router'
8
9
  import type { StrictOrFrom } from './utils'
9
- import type { Expand } from '@tanstack/router-core'
10
+ import type { Expand, ThrowOrOptional } from '@tanstack/router-core'
10
11
 
11
12
  export interface UseParamsBaseOptions<
12
13
  TRouter extends AnyRouter,
13
14
  TFrom,
14
15
  TStrict extends boolean,
16
+ TThrow extends boolean,
15
17
  TSelected,
16
18
  TStructuralSharing,
17
19
  > {
18
20
  select?: (
19
21
  params: ResolveParams<TRouter, TFrom, TStrict>,
20
22
  ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>
23
+ shouldThrow?: TThrow
21
24
  }
22
25
 
23
26
  export type UseParamsOptions<
24
27
  TRouter extends AnyRouter,
25
28
  TFrom extends string | undefined,
26
29
  TStrict extends boolean,
30
+ TThrow extends boolean,
27
31
  TSelected,
28
32
  TStructuralSharing,
29
33
  > = StrictOrFrom<TRouter, TFrom, TStrict> &
30
- UseParamsBaseOptions<TRouter, TFrom, TStrict, TSelected, TStructuralSharing> &
34
+ UseParamsBaseOptions<
35
+ TRouter,
36
+ TFrom,
37
+ TStrict,
38
+ TThrow,
39
+ TSelected,
40
+ TStructuralSharing
41
+ > &
31
42
  StructuralSharingOption<TRouter, TSelected, TStructuralSharing>
32
43
 
33
44
  export type ResolveParams<
@@ -55,7 +66,8 @@ export type UseParamsRoute<out TFrom> = <
55
66
  opts?: UseParamsBaseOptions<
56
67
  TRouter,
57
68
  TFrom,
58
- true,
69
+ /* TStrict */ true,
70
+ /* TThrow */ true,
59
71
  TSelected,
60
72
  TStructuralSharing
61
73
  > &
@@ -66,6 +78,7 @@ export function useParams<
66
78
  TRouter extends AnyRouter = RegisteredRouter,
67
79
  const TFrom extends string | undefined = undefined,
68
80
  TStrict extends boolean = true,
81
+ TThrow extends boolean = true,
69
82
  TSelected = unknown,
70
83
  TStructuralSharing extends boolean = boolean,
71
84
  >(
@@ -73,16 +86,21 @@ export function useParams<
73
86
  TRouter,
74
87
  TFrom,
75
88
  TStrict,
89
+ ThrowConstraint<TStrict, TThrow>,
76
90
  TSelected,
77
91
  TStructuralSharing
78
92
  >,
79
- ): UseParamsResult<TRouter, TFrom, TStrict, TSelected> {
93
+ ): ThrowOrOptional<
94
+ UseParamsResult<TRouter, TFrom, TStrict, TSelected>,
95
+ TThrow
96
+ > {
80
97
  return useMatch({
81
98
  from: opts.from!,
82
99
  strict: opts.strict,
100
+ shouldThrow: opts.shouldThrow,
83
101
  structuralSharing: opts.structuralSharing,
84
102
  select: (match: any) => {
85
103
  return opts.select ? opts.select(match.params) : match.params
86
104
  },
87
- } as any) as UseParamsResult<TRouter, TFrom, TStrict, TSelected>
105
+ }) as any
88
106
  }
package/src/useSearch.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  import { useMatch } from './useMatch'
2
+ import type { ThrowConstraint } from './useMatch'
2
3
  import type {
3
4
  StructuralSharingOption,
4
5
  ValidateSelected,
@@ -6,28 +7,38 @@ import type {
6
7
  import type { FullSearchSchema, RouteById } from './routeInfo'
7
8
  import type { AnyRouter, RegisteredRouter } from './router'
8
9
  import type { StrictOrFrom } from './utils'
9
- import type { Expand } from '@tanstack/router-core'
10
+ import type { Expand, ThrowOrOptional } from '@tanstack/router-core'
10
11
 
11
12
  export interface UseSearchBaseOptions<
12
13
  TRouter extends AnyRouter,
13
14
  TFrom,
14
15
  TStrict extends boolean,
16
+ TThrow extends boolean,
15
17
  TSelected,
16
18
  TStructuralSharing,
17
19
  > {
18
20
  select?: (
19
21
  state: ResolveSearch<TRouter, TFrom, TStrict>,
20
22
  ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>
23
+ shouldThrow?: TThrow
21
24
  }
22
25
 
23
26
  export type UseSearchOptions<
24
27
  TRouter extends AnyRouter,
25
28
  TFrom,
26
29
  TStrict extends boolean,
30
+ TThrow extends boolean,
27
31
  TSelected,
28
32
  TStructuralSharing,
29
33
  > = StrictOrFrom<TRouter, TFrom, TStrict> &
30
- UseSearchBaseOptions<TRouter, TFrom, TStrict, TSelected, TStructuralSharing> &
34
+ UseSearchBaseOptions<
35
+ TRouter,
36
+ TFrom,
37
+ TStrict,
38
+ TThrow,
39
+ TSelected,
40
+ TStructuralSharing
41
+ > &
31
42
  StructuralSharingOption<TRouter, TSelected, TStructuralSharing>
32
43
 
33
44
  export type UseSearchResult<
@@ -55,7 +66,8 @@ export type UseSearchRoute<out TFrom> = <
55
66
  opts?: UseSearchBaseOptions<
56
67
  TRouter,
57
68
  TFrom,
58
- true,
69
+ /* TStrict */ true,
70
+ /* TThrow */ true,
59
71
  TSelected,
60
72
  TStructuralSharing
61
73
  > &
@@ -66,6 +78,7 @@ export function useSearch<
66
78
  TRouter extends AnyRouter = RegisteredRouter,
67
79
  const TFrom extends string | undefined = undefined,
68
80
  TStrict extends boolean = true,
81
+ TThrow extends boolean = true,
69
82
  TSelected = unknown,
70
83
  TStructuralSharing extends boolean = boolean,
71
84
  >(
@@ -73,16 +86,21 @@ export function useSearch<
73
86
  TRouter,
74
87
  TFrom,
75
88
  TStrict,
89
+ ThrowConstraint<TStrict, TThrow>,
76
90
  TSelected,
77
91
  TStructuralSharing
78
92
  >,
79
- ): UseSearchResult<TRouter, TFrom, TStrict, TSelected> {
93
+ ): ThrowOrOptional<
94
+ UseSearchResult<TRouter, TFrom, TStrict, TSelected>,
95
+ TThrow
96
+ > {
80
97
  return useMatch({
81
98
  from: opts.from!,
82
99
  strict: opts.strict,
100
+ shouldThrow: opts.shouldThrow,
83
101
  structuralSharing: opts.structuralSharing,
84
102
  select: (match: any) => {
85
103
  return opts.select ? opts.select(match.search) : match.search
86
104
  },
87
- }) as UseSearchResult<TRouter, TFrom, TStrict, TSelected>
105
+ }) as any
88
106
  }