[React] React Router: activeStyle & activeClassName


react-router provides two props for setting a specific style on a Link component whose path matches our current route. activeStyle allows for an inline style while activeClassName allows for an class defined in an external stylesheet.

 

const Links = () =>
    <nav >
        <Link activeStyle={{color: 'green'}} to="/">Home</Link>
        <Link activeStyle={{color: 'green'}} to="/about">About</Link>
        <Link activeClassName="active" to="/contact">Contact</Link>
    </nav>;

 

.active{
    color: green;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM