We often need to be able to apply style to navigation links based on the current route. In React Router v4 you can easily accomplish this with the NavLink component. In this lesson, we will step through three ways to accomplish styling links through the use of an active class with the NavLink component.

There are three ways to check an link is active or not and add active class for it:

const isLinkActive = (match, location) => {
return match
}; const Nav = () => (
<nav>
<NavLink to="/" exact activeStyle={{color: 'pink'}}>Home</NavLink>
<NavLink to="/about" activeClassName="active">About</NavLink>
<NavLink replace
to={{pathname: '/contact'}}
isActive={isLinkActive}
activeClassName="active"
>Contact</NavLink>
</nav>
);

'isActive' prop allows you to decide whether or not to apply active class.

最新文章

  1. 如何实现一个php框架系列文章【4】url路由管理
  2. Jmeter+TCP\Scoket(8583)报文压力测试
  3. shadow Dom(shadowRoot) 访问
  4. 如何更好的通过Inflate layout的方式来实现自定义view
  5. VS2010 自动跳过代码现象
  6. 获得 LayoutInflater 实例的三种方式
  7. javascript 我是广告
  8. log4cxx入门第一篇--一个小例子
  9. Python学习--20 Web开发
  10. 老李分享:Robotium创建Note的实例
  11. 英语学习笔记---01---新概念第一册---Lesson 1 Excuse me!
  12. PGM:图模型学习概述
  13. LCD 常用的客观效果指标和测试方法
  14. SpringMVC解决跨域的两种方案
  15. 部署alinode监控线上应用
  16. python中os模块操作目录与文件名小结
  17. Maven遇到github引用的项目有bug怎么办?
  18. spring cloud: 使用consul来替换eureka
  19. lambda表达式底层处理机制
  20. [转]Windows7:Visual Studio 2008试用版的评估期已经结束解决方法

热门文章

  1. Android怎样实现毛玻璃效果之Android高级模糊技术
  2. git仓库搭建
  3. java中那些已经有的好用轮子
  4. iOS开发 非常全的三方库、插件、大牛博客等等
  5. 安装filezilla client报错libgnutls版本旧
  6. Spring拦截器和Servlet过滤器区别
  7. Qt的一些开发技巧
  8. POJ 3259 Wormholes 邻接表的SPFA判断负权回路
  9. Aamazon Web Service EC2 Ubuntu 新建用户而且用ssh连接host
  10. 不可摸数 【杭电-HDOJ-1999】 附题