React-Router-DOM学习笔记
基础知识
1.BrowserRouter (as Router,给BrowserRouter起一个别名)
2.Route 匹配路径,导入组件
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181116214522023-507156422.jpg)
3.Fragment 用来构建根组件
4.包容性,react-router-dom原始支持包容性
排他性需要引入switch,Switch的特点是从上往下读,只要有一个匹配成功,就不会往下读(Switch是由包容性变成排他性的一个重要组件)
5.编程式导航 Link to属性
(link在内部做了一个操作,把标签变成了a标签)
6.Redirect组件(重定向)
from属性 exact精准匹配 to属性
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181116223248429-1728227103.jpg)
7.高亮效果 NavLink
方式一 activeClassName (string) (注意这里的activeClassName的C是大写)
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181116224349711-2052690477.jpg)
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181116224456418-555779276.jpg)
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181116224618856-1515949513.jpg)
方式二 activeStyle (Object)
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181116225454444-200955453.jpg)
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181116225503425-1648725600.jpg)
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181116225510715-655381764.jpg)
8.匹配子路由
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181116233605981-568595358.jpg)
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181116233719247-1971860535.jpg)
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181117090000999-209282259.jpg)
9.动态路由
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181117215314101-784927117.jpg)
10.Route组件的render和children方法
render方法只有在路由匹配时才触发
children方法不管路由匹不匹配都会触发
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181118145117119-1792767786.jpg)
11.自定义组件
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181118152845454-154519863.jpg)
12.自定义Link组件
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181118154246708-1904456455.jpg)
13.withRouter
![](https://img2018.cnblogs.com/blog/1459089/201811/1459089-20181118160315704-1464162014.jpg)