Question: Active Link Highlight
See original GitHub issueHello
How can I highlight a link that has been clicked. For example the supersimple code below will highlight link named ‘about’ in blue, for a second, after which it flickers back to normal navbar. Albeit I been able to in many ways custom style your navbar I can not for all the tea in the world figure out how to highlight an active link and keep it highlighted. For your info, I am using BrowserRouter, but not sure if that has any relevance…
Simple code (the blue highlight flickers when you click but then navbar link goes back to normal look and feel)
export default class Example extends React.Component {
constructor(props) {
super(props);
this.toggle = this.toggle.bind(this);
this.state = {
isOpen: false,
};
}
toggle() {
this.setState({
isOpen: !this.state.isOpen
});
}
onClick() {
this.setState({
bgColor:'blue'
})
}
render() {
return (
<Navbar color="light" light expand="sm">
<NavbarBrand href="/">BLEBB BLEBB</NavbarBrand>
<NavbarToggler onClick={this.toggle}/>
<Collapse isOpen={this.state.isOpen} navbar>
<Nav className="ml-auto" navbar>
<NavItem className="navLink">
<NavLink href="/" onClick={this.onClick.bind(this)} style={{backgroundColor:this.state.bgColor}}>About</NavLink>
</NavItem>
<NavItem className="navLink">
<NavLink href="/work">Work</NavLink>
</NavItem>
<NavItem className="navLink">
<NavLink href="/contact">Contact</NavLink>
</NavItem>
</Nav>
</Collapse>
</Navbar>
);
}
Thanks in Advance, fellow tea drinkers
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:10 (2 by maintainers)
Top Results From Across the Web
How to highlight active links - html - Stack Overflow
I want to have clicked or active links turn purple so that one can tell which link is active. I tried a couple...
Read more >how to highlight active nav-item? - Material Design for Bootstrap
A beginner question... How do I highlight the active nav-link so that it is clearly visible to the end user? In the example...
Read more >Material UI - Navigation and Active Link Highlighting - YouTube
Check out Filestack - https://calcur.tech/filestack FREE Courses (100+ hours) - https://calcur.tech/all-in-ones Python Course ...
Read more >how to make the active link highlighted - WordPress.org
Hi, I tried using custom css to style the menu bar, but I cant get the active page to highlighted with yellow. how...
Read more >Highlight the active/current (pressed) button html by default
Hi All, this is for Service Portal. I have 2 buttons Active and Closed I want the Active button to be highlighted/selected by...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello,
thanks for your answer, I had to interpolate the solution slightly. When I tried the code on the link in your reply, even if I copied and pasted the class, I recieved that activeClassName is not supported.
However, the below worked, and my menu now highlights nicely. That being sad I have little idea at this point what
tag={}
does. Could someone kindly explain what it does? After explaining that, you can close this as I now got it working. Unless, my solution is errorneous in some way!Thanks, got it all working now! Moving on!