File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
- import { Link } from 'react-router-dom' ;
3
+ import { Link , NavLink } from 'react-router-dom' ;
4
4
5
5
let hashFragment = '' ;
6
6
let observer = null ;
@@ -41,7 +41,7 @@ function hashLinkScroll() {
41
41
} , 0 ) ;
42
42
}
43
43
44
- export function HashLink ( props ) {
44
+ export function genericHashLink ( props , As ) {
45
45
function handleClick ( e ) {
46
46
reset ( ) ;
47
47
if ( props . onClick ) props . onClick ( e ) ;
@@ -52,14 +52,25 @@ export function HashLink(props) {
52
52
}
53
53
if ( hashFragment !== '' ) hashLinkScroll ( ) ;
54
54
}
55
- return < Link { ...props } onClick = { handleClick } > { props . children } </ Link > ;
55
+ return < As { ...props } onClick = { handleClick } > { props . children } </ As > ;
56
+ }
57
+
58
+ export function HashLink ( props ) {
59
+ return genericHashLink ( props , Link ) ;
56
60
}
57
61
58
- HashLink . propTypes = {
62
+ export function NavHashLink ( props ) {
63
+ return genericHashLink ( props , NavLink ) ;
64
+ }
65
+
66
+ const propTypes = {
59
67
onClick : PropTypes . func ,
60
68
children : PropTypes . node ,
61
69
to : PropTypes . oneOfType ( [
62
70
PropTypes . string ,
63
71
PropTypes . object ,
64
72
] ) ,
65
73
} ;
74
+
75
+ HashLink . propTypes = propTypes ;
76
+ NavHashLink . propTypes = propTypes ;
You can’t perform that action at this time.
0 commit comments