0
import React from 'react'
import { Link, withRouter } from 'react-router-dom'
const isActive= (history, path) => {
if (history.location.pathname === path) return { active: 'active' }
else return { color: 'pink' }
}
const App= ({ history }) => (
<nav id="sidebar" className="fixed pt-3">
<ul className="custom-scrollbar">
<li><Link to="/dashboard" className={isActive(history, "/dashboard")}><span className="ti-home mr-3"></span>Home</Link></li>
</ul>
</nav>
)
ReactDOM.render(<App />, document.querySelector("#app"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="app"></div>
It didn’t work Maycon
– Js Dev
Try to take the keys from the classname: <li><Link to="/Dashboard" classname=isActive(history, "/Dashboard")><span classname="ti-home mr-3"></span>Home</Link></li>
– Maycon F. Castro
If not, try it like this: <li><Link to="/Dashboard" classname={history.location.pathname == "/Dashboard" ? 'active' 'pink'}><span classname="ti-home mr-3"></span>Home</Link></li>
– Maycon F. Castro
Now Sam! Thank you so much!!!!
– Js Dev