File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,16 @@ const NavLink = props => {
31
31
) ;
32
32
} ;
33
33
34
+ useEffect ( ( ) => {
35
+ pathnameToActive ( window . location . pathname ) ;
36
+
37
+ if ( typeof active === 'string' ) {
38
+ History . onChange ( ( ) => {
39
+ pathnameToActive ( window . location . pathname ) ;
40
+ } ) ;
41
+ }
42
+ } , [ active ] ) ;
43
+
34
44
const incrementClicks = ( ) => {
35
45
if ( ! disabled && setProps ) {
36
46
setProps ( {
@@ -40,18 +50,11 @@ const NavLink = props => {
40
50
}
41
51
} ;
42
52
43
- useEffect ( ( ) => {
44
- // get initial pathname
45
- pathnameToActive ( window . location . pathname ) ;
46
-
47
- // add event listener to update on change
48
- History . onChange ( ( ) => pathnameToActive ( window . location . pathname ) ) ;
49
- } , [ ] ) ;
50
-
51
53
const classes = classNames ( className , 'nav-link' , {
52
54
active : linkActive ,
53
55
disabled
54
56
} ) ;
57
+
55
58
return (
56
59
< Link
57
60
className = { classes }
You can’t perform that action at this time.
0 commit comments