Nav works, home link is always active other links are OK. Adding as component, no props.
HTML
<Menu/>
CSS
.active{
background-color:#ff6a00;
}
JS
import React, { Component } from 'react';
import './menu.css';
import { NavLink } from 'react-router-dom'
export default class TopMenu extends Component {
render() {
return (
<div className="ui container">
<div className="ui stackable menu">
<div className="item">
<NavLink to='/' >
<i aria-hidden="true" className="home icon" ></i>
Home
</NavLink>
</div>
<div className="item">
<NavLink to='/about' >
<i aria-hidden="true" className="circle info icon" >
</i>
About
</NavLink>
</div>
<div className="item" >
<NavLink to='/Settings'>
<i aria-hidden="true" className="cogs icon red" ></i>
Settings
</NavLink>
</div>
</div>
</div>
);
}
}
Ideas anyone, why is home always active ?
The NavLink is used when you want to highlight a link as active. So, on every routing to a page, the link is highlighted according to the activeClassName . Link is for links that need no highlighting. And a is for external links.
you have to specify the exact prop for your home route '/' because this matches all the other routes, that's why '/' is always active.
<NavLink to='/' exact={true}>
<i aria-hidden="true" className="home icon" ></i>
Home
</NavLink>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With