@@ -72,17 +72,26 @@ function hashLinkScroll(timeout) {
72
72
73
73
export function genericHashLink ( As ) {
74
74
return React . forwardRef ( ( props , ref ) => {
75
+ let linkHash = '' ;
76
+ if ( typeof props . to === 'string' && props . to . includes ( '#' ) ) {
77
+ linkHash = `#${ props . to . split ( '#' ) . slice ( 1 ) . join ( '#' ) } ` ;
78
+ } else if (
79
+ typeof props . to === 'object' &&
80
+ typeof props . to . hash === 'string'
81
+ ) {
82
+ linkHash = props . to . hash ;
83
+ }
84
+
85
+ const passDownProps = { } ;
86
+ if ( As === NavLink ) {
87
+ passDownProps . isActive = ( match , location ) =>
88
+ match && match . isExact && location . hash === linkHash ;
89
+ }
90
+
75
91
function handleClick ( e ) {
76
92
reset ( ) ;
93
+ hashFragment = linkHash ;
77
94
if ( props . onClick ) props . onClick ( e ) ;
78
- if ( typeof props . to === 'string' && props . to . includes ( '#' ) ) {
79
- hashFragment = `#${ props . to . split ( '#' ) . slice ( 1 ) . join ( '#' ) } ` ;
80
- } else if (
81
- typeof props . to === 'object' &&
82
- typeof props . to . hash === 'string'
83
- ) {
84
- hashFragment = props . to . hash ;
85
- }
86
95
if ( hashFragment !== '' ) {
87
96
scrollFunction =
88
97
props . scroll ||
@@ -95,7 +104,7 @@ export function genericHashLink(As) {
95
104
}
96
105
const { scroll, smooth, timeout, ...filteredProps } = props ;
97
106
return (
98
- < As { ...filteredProps } onClick = { handleClick } ref = { ref } >
107
+ < As { ...passDownProps } { ... filteredProps } onClick = { handleClick } ref = { ref } >
99
108
{ props . children }
100
109
</ As >
101
110
) ;
0 commit comments