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 => {
3131 ) ;
3232 } ;
3333
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+
3444 const incrementClicks = ( ) => {
3545 if ( ! disabled && setProps ) {
3646 setProps ( {
@@ -40,18 +50,11 @@ const NavLink = props => {
4050 }
4151 } ;
4252
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-
5153 const classes = classNames ( className , 'nav-link' , {
5254 active : linkActive ,
5355 disabled
5456 } ) ;
57+
5558 return (
5659 < Link
5760 className = { classes }
You can’t perform that action at this time.
0 commit comments