@@ -5,6 +5,7 @@ import type { QueryString } from "../types/query-string";
55import { AnyJson } from "../types" ;
66import { Paths } from "../types/paths" ;
77import { TextFragment } from "../utils/text-fragment" ;
8+ import { QueryStringMapper } from "../utils/mappers" ;
89
910const isLeftClick = ( e : React . MouseEvent ) => e . button === 0 ;
1011
@@ -16,24 +17,25 @@ type QueryAndPaths<Path extends string> = (Paths.Has<Path> extends true ? { path
1617 ( QueryString . Has < Path > extends true ? { query : NonNullable < QueryString . Parse < Path > > } : { query ?: never } ) ;
1718
1819export type LinkProps < Path extends string > = Omit < AnchorProps , "href" | "onClick" > & {
19- href : Path ;
20- state ?: AnyJson ;
21- replace ?: boolean ;
2220 fragments ?: TextFragment [ ] ;
21+ href : Path ;
2322 onClick ?: ( event : Parameters < NonNullable < AnchorProps [ "onClick" ] > > [ 0 ] , pathAndQuery : QueryAndPaths < Path > ) => void ;
23+ parsers ?: Partial < QueryStringMapper < string > > ;
24+ replace ?: boolean ;
25+ state ?: AnyJson ;
2426} & QueryAndPaths < Path > ;
2527
2628const httpRegex = / ^ h t t p s ? : \/ \/ / ;
2729
2830export const Link : < TPath extends string > ( props : LinkProps < TPath > ) => React . ReactElement = forwardRef (
2931 < TPath extends string > (
30- { href, state, replace = false , onClick, query, paths, fragments, ...props } : LinkProps < TPath > ,
32+ { href, state, replace = false , onClick, parsers , query, paths, fragments, ...props } : LinkProps < TPath > ,
3133 ref : React . Ref < HTMLAnchorElement >
3234 ) => {
3335 const { push, replace : _replace } = useNavigation ( ) ;
3436 const contextHref = useHref ( ) ;
3537 const basename = useBasename ( ) ;
36- const _href = httpRegex . test ( href ) ? href : join ( basename , mergeUrlEntities ( href , paths , query , undefined , fragments ) ) ;
38+ const _href = httpRegex . test ( href ) ? href : join ( basename , mergeUrlEntities ( href , paths , query , parsers , fragments ) ) ;
3739 const _onClick : NonNullable < AnchorProps [ "onClick" ] > = ( event ) => {
3840 if ( props . target === undefined && props . target !== "_self" ) event . preventDefault ( ) ;
3941 if ( _href === contextHref ) return ;
0 commit comments