Skip to content

Commit e45ecaf

Browse files
authored
Merge pull request #499 from facultyai/navlink-patch
NavLink fix
2 parents e9ae301 + 00ff8df commit e45ecaf

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/components/nav/NavLink.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff 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}

0 commit comments

Comments
 (0)