Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

NavItem Active State Faulty #361

Closed
Thomas-Smyth opened this issue Nov 16, 2018 · 3 comments · Fixed by #383
Closed

NavItem Active State Faulty #361

Thomas-Smyth opened this issue Nov 16, 2018 · 3 comments · Fixed by #383

Comments

@Thomas-Smyth
Copy link
Contributor

Hello all,

It seems that the active states of NavItems are being incorrectly set when using react-router.

No need to supply my own code to show this as the issue is present in the example section of this repository.

When most pages are being accessed, it shows both the Home page and the currently selected page as active. For example, in this gallery page, both the Gallery page NavItem and the Home page NavItem are active.

To me, without analysing the repository code, it looks as if the system to show which NavItem is active checks the NavItem paths to see if they contain the current path. I do not believe this should be the case as it causes paths such as / and /blog to both be shown as active when only one should be active at a time. However, this should be the case for all sublinks / links in the dropdowns from the navbar.

@Greg-Hamel
Copy link
Contributor

@Thomas-Smyth thanks for looking into this. It’s been on my list of things to look at for a while. I’ll have a look and report back soon.

@Thomas-Smyth
Copy link
Contributor Author

Thomas-Smyth commented Dec 2, 2018

Done some more experimenting, it seems that the active state is being passed correctly to the Nav.Link component, but it's children something goes wrong. That seems to do with React Router's exact prop not being present.

Issue

Edit:
As I suspected when adding exact to RootComponent in the NavLink component file it renders correctly.

  return RootComponent ? (
    <RootComponent exact className={classes} to={to}>
      {childrenForAll}
    </RootComponent>
  ) : (
    <a className={classes} href={to} ref={rootRef}>
      {childrenForAll}
    </a>
  );

Though this obviously isn't a good fix. I just don't understand React and React Router enough to fix it. I'm still a newbie when it comes to React.

@jonthomp
Copy link
Contributor

jonthomp commented Dec 5, 2018

🎉 This issue has been resolved in version 1.27.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants