@tanstack/react-router 1.58.7 → 1.58.11
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 +1 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +20 -17
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +1 -1
- package/dist/cjs/routeInfo.d.cts +2 -2
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useNavigate.d.cts +1 -2
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/link.d.ts +20 -17
- package/dist/esm/link.js +1 -1
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/route.d.ts +1 -1
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/routeInfo.d.ts +2 -2
- package/dist/esm/useNavigate.d.ts +1 -2
- package/dist/esm/useNavigate.js.map +1 -1
- package/package.json +1 -1
- package/src/index.tsx +1 -0
- package/src/link.tsx +48 -32
- package/src/route.ts +1 -1
- package/src/routeInfo.ts +10 -7
- package/src/useNavigate.tsx +4 -4
package/src/index.tsx
CHANGED
package/src/link.tsx
CHANGED
|
@@ -28,6 +28,7 @@ import type {
|
|
|
28
28
|
} from './routeInfo'
|
|
29
29
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
30
30
|
import type {
|
|
31
|
+
Constrain,
|
|
31
32
|
Expand,
|
|
32
33
|
MakeDifferenceOptional,
|
|
33
34
|
NoInfer,
|
|
@@ -36,6 +37,7 @@ import type {
|
|
|
36
37
|
Updater,
|
|
37
38
|
WithoutEmpty,
|
|
38
39
|
} from './utils'
|
|
40
|
+
import type { ReactNode } from 'react'
|
|
39
41
|
|
|
40
42
|
export type CleanPath<T extends string> = T extends `${infer L}//${infer R}`
|
|
41
43
|
? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`>
|
|
@@ -413,7 +415,7 @@ export type IsRequired<
|
|
|
413
415
|
TTo,
|
|
414
416
|
> =
|
|
415
417
|
ResolveRelativePath<TFrom, TTo> extends infer TPath
|
|
416
|
-
?
|
|
418
|
+
? undefined extends TPath
|
|
417
419
|
? never
|
|
418
420
|
: TPath extends CatchAllPaths<TrailingSlashOptionByRouter<TRouter>>
|
|
419
421
|
? never
|
|
@@ -820,9 +822,9 @@ export function useLinkProps<
|
|
|
820
822
|
}
|
|
821
823
|
|
|
822
824
|
return {
|
|
825
|
+
...rest,
|
|
823
826
|
...resolvedActiveProps,
|
|
824
827
|
...resolvedInactiveProps,
|
|
825
|
-
...rest,
|
|
826
828
|
href: disabled
|
|
827
829
|
? undefined
|
|
828
830
|
: next.maskedLocation
|
|
@@ -847,50 +849,65 @@ export function useLinkProps<
|
|
|
847
849
|
}
|
|
848
850
|
}
|
|
849
851
|
|
|
852
|
+
type UseLinkReactProps<TComp> = TComp extends keyof JSX.IntrinsicElements
|
|
853
|
+
? JSX.IntrinsicElements[TComp]
|
|
854
|
+
: React.PropsWithoutRef<
|
|
855
|
+
TComp extends React.ComponentType<infer TProps> ? TProps : never
|
|
856
|
+
> &
|
|
857
|
+
React.RefAttributes<
|
|
858
|
+
TComp extends
|
|
859
|
+
| React.FC<{ ref: infer TRef }>
|
|
860
|
+
| React.Component<{ ref: infer TRef }>
|
|
861
|
+
? TRef
|
|
862
|
+
: never
|
|
863
|
+
>
|
|
864
|
+
|
|
850
865
|
export type UseLinkPropsOptions<
|
|
851
866
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
852
867
|
TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
|
|
853
868
|
TTo extends string | undefined = '.',
|
|
854
869
|
TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,
|
|
855
870
|
TMaskTo extends string = '.',
|
|
856
|
-
> = ActiveLinkOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &
|
|
857
|
-
|
|
871
|
+
> = ActiveLinkOptions<'a', TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &
|
|
872
|
+
UseLinkReactProps<'a'>
|
|
858
873
|
|
|
859
874
|
export type ActiveLinkOptions<
|
|
875
|
+
TComp = 'a',
|
|
860
876
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
861
877
|
TFrom extends string = string,
|
|
862
878
|
TTo extends string | undefined = '.',
|
|
863
879
|
TMaskFrom extends string = TFrom,
|
|
864
880
|
TMaskTo extends string = '.',
|
|
865
|
-
> = LinkOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &
|
|
881
|
+
> = LinkOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &
|
|
882
|
+
ActiveLinkOptionProps<TComp>
|
|
866
883
|
|
|
867
|
-
type
|
|
868
|
-
|
|
884
|
+
type ActiveLinkProps<TComp> = Partial<
|
|
885
|
+
LinkComponentReactProps<TComp> & {
|
|
869
886
|
[key: `data-${string}`]: unknown
|
|
870
|
-
}
|
|
871
|
-
'children'
|
|
887
|
+
}
|
|
872
888
|
>
|
|
873
889
|
|
|
874
|
-
export interface ActiveLinkOptionProps {
|
|
890
|
+
export interface ActiveLinkOptionProps<TComp = 'a'> {
|
|
875
891
|
/**
|
|
876
892
|
* A function that returns additional props for the `active` state of this link.
|
|
877
893
|
* These props override other props passed to the link (`style`'s are merged, `className`'s are concatenated)
|
|
878
894
|
*/
|
|
879
|
-
activeProps?:
|
|
895
|
+
activeProps?: ActiveLinkProps<TComp> | (() => ActiveLinkProps<TComp>)
|
|
880
896
|
/**
|
|
881
897
|
* A function that returns additional props for the `inactive` state of this link.
|
|
882
898
|
* These props override other props passed to the link (`style`'s are merged, `className`'s are concatenated)
|
|
883
899
|
*/
|
|
884
|
-
inactiveProps?:
|
|
900
|
+
inactiveProps?: ActiveLinkProps<TComp> | (() => ActiveLinkProps<TComp>)
|
|
885
901
|
}
|
|
886
902
|
|
|
887
903
|
export type LinkProps<
|
|
904
|
+
TComp = 'a',
|
|
888
905
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
889
906
|
TFrom extends string = string,
|
|
890
907
|
TTo extends string | undefined = '.',
|
|
891
908
|
TMaskFrom extends string = TFrom,
|
|
892
909
|
TMaskTo extends string = '.',
|
|
893
|
-
> = ActiveLinkOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &
|
|
910
|
+
> = ActiveLinkOptions<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &
|
|
894
911
|
LinkPropsChildren
|
|
895
912
|
|
|
896
913
|
export interface LinkPropsChildren {
|
|
@@ -903,32 +920,29 @@ export interface LinkPropsChildren {
|
|
|
903
920
|
}) => React.ReactNode)
|
|
904
921
|
}
|
|
905
922
|
|
|
906
|
-
type LinkComponentReactProps<TComp> =
|
|
907
|
-
TComp
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
? Omit<React.HTMLProps<TComp>, 'children' | 'preload'>
|
|
911
|
-
: never
|
|
912
|
-
> &
|
|
913
|
-
React.RefAttributes<
|
|
914
|
-
TComp extends
|
|
915
|
-
| React.FC<{ ref: infer TRef }>
|
|
916
|
-
| React.Component<{ ref: infer TRef }>
|
|
917
|
-
? TRef
|
|
918
|
-
: TComp extends keyof React.JSX.IntrinsicElements
|
|
919
|
-
? React.ComponentRef<TComp>
|
|
920
|
-
: never
|
|
921
|
-
>
|
|
923
|
+
type LinkComponentReactProps<TComp> = Omit<
|
|
924
|
+
UseLinkReactProps<TComp>,
|
|
925
|
+
keyof CreateLinkProps
|
|
926
|
+
>
|
|
922
927
|
|
|
923
928
|
export type LinkComponentProps<
|
|
924
|
-
TComp,
|
|
929
|
+
TComp = 'a',
|
|
925
930
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
926
931
|
TFrom extends string = string,
|
|
927
932
|
TTo extends string | undefined = '.',
|
|
928
933
|
TMaskFrom extends string = TFrom,
|
|
929
934
|
TMaskTo extends string = '.',
|
|
930
935
|
> = LinkComponentReactProps<TComp> &
|
|
931
|
-
LinkProps<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>
|
|
936
|
+
LinkProps<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo>
|
|
937
|
+
|
|
938
|
+
export type CreateLinkProps = LinkProps<
|
|
939
|
+
any,
|
|
940
|
+
any,
|
|
941
|
+
string,
|
|
942
|
+
string,
|
|
943
|
+
string,
|
|
944
|
+
string
|
|
945
|
+
>
|
|
932
946
|
|
|
933
947
|
export type LinkComponent<TComp> = <
|
|
934
948
|
TRouter extends RegisteredRouter = RegisteredRouter,
|
|
@@ -940,7 +954,9 @@ export type LinkComponent<TComp> = <
|
|
|
940
954
|
props: LinkComponentProps<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,
|
|
941
955
|
) => React.ReactElement
|
|
942
956
|
|
|
943
|
-
export function createLink<const TComp>(
|
|
957
|
+
export function createLink<const TComp>(
|
|
958
|
+
Comp: Constrain<TComp, any, (props: CreateLinkProps) => ReactNode>,
|
|
959
|
+
): LinkComponent<TComp> {
|
|
944
960
|
return React.forwardRef(function CreatedLink(props, ref) {
|
|
945
961
|
return <Link {...(props as any)} _asChild={Comp} ref={ref} />
|
|
946
962
|
}) as any
|
package/src/route.ts
CHANGED
|
@@ -1555,7 +1555,7 @@ export type RouteMask<TRouteTree extends AnyRoute> = {
|
|
|
1555
1555
|
|
|
1556
1556
|
export function createRouteMask<
|
|
1557
1557
|
TRouteTree extends AnyRoute,
|
|
1558
|
-
TFrom extends
|
|
1558
|
+
TFrom extends string,
|
|
1559
1559
|
TTo extends string,
|
|
1560
1560
|
>(
|
|
1561
1561
|
opts: {
|
package/src/routeInfo.ts
CHANGED
|
@@ -95,11 +95,13 @@ export type CodeRoutePaths<TRouteTree extends AnyRoute> =
|
|
|
95
95
|
? TRoutes['fullPath']
|
|
96
96
|
: never
|
|
97
97
|
|
|
98
|
-
export type RoutePaths<TRouteTree extends AnyRoute> =
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
export type RoutePaths<TRouteTree extends AnyRoute> = unknown extends TRouteTree
|
|
99
|
+
? string
|
|
100
|
+
:
|
|
101
|
+
| (InferFileRouteTypes<TRouteTree> extends never
|
|
102
|
+
? CodeRoutePaths<TRouteTree>
|
|
103
|
+
: InferFileRouteTypes<TRouteTree>['fullPaths'])
|
|
104
|
+
| '/'
|
|
103
105
|
|
|
104
106
|
export type RouteToPathAlwaysTrailingSlash<TRoute extends AnyRoute> =
|
|
105
107
|
TRoute['path'] extends '/'
|
|
@@ -160,8 +162,9 @@ export type FileRouteToPath<
|
|
|
160
162
|
export type RouteToPath<
|
|
161
163
|
TRouter extends AnyRouter,
|
|
162
164
|
TRouteTree extends AnyRoute,
|
|
163
|
-
> =
|
|
164
|
-
|
|
165
|
+
> = unknown extends TRouter
|
|
166
|
+
? string
|
|
167
|
+
: InferFileRouteTypes<TRouter['routeTree']> extends never
|
|
165
168
|
? CodeRouteToPath<TRouter, TRouteTree>
|
|
166
169
|
: FileRouteToPath<TRouter>
|
|
167
170
|
|
package/src/useNavigate.tsx
CHANGED
|
@@ -50,10 +50,10 @@ export function useNavigate<
|
|
|
50
50
|
|
|
51
51
|
export function Navigate<
|
|
52
52
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
53
|
-
TFrom extends
|
|
54
|
-
TTo extends string | undefined =
|
|
55
|
-
TMaskFrom extends
|
|
56
|
-
TMaskTo extends string = '',
|
|
53
|
+
TFrom extends string = string,
|
|
54
|
+
TTo extends string | undefined = '.',
|
|
55
|
+
TMaskFrom extends string = TFrom,
|
|
56
|
+
TMaskTo extends string = '.',
|
|
57
57
|
>(props: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): null {
|
|
58
58
|
const { navigate } = useRouter()
|
|
59
59
|
|