react路由补充部分(exact、八个路由示例)

1、exact
exact是Route下的一条属性,一般而言,react路由会匹配所有匹配到的路由组价,exact能够使得路由的匹配更严格一些。

exact的值为bool型,为true是表示严格匹配,为false时为正常匹配。

如在exact为true时,’/link’与’/’是不匹配的,但是在false的情况下它们又是匹配的。

一个常用的场景是这样的:

<Route path='/' component={Home} />
<Route path='/page' component={Page}>
//这种情况下,如果匹配路由path='/page',那么会把Home也会展示出来。

所以我们经常添加exact来解决上述问题。

<Route exact path='/' component={Home} />
<Route path='/page' component={Page} />

2、下面是八个react路由示例:(github上面)。

https://github.com/liwudi/react-router-dom1.git

https://github.com/liwudi/react-router-dom2.git

https://github.com/liwudi/react-router-dom3.git

https://github.com/liwudi/react-router-dom4.git

https://github.com/liwudi/react-router-dom5.git

https://github.com/liwudi/react-router-dom6.git

https://github.com/liwudi/react-router-dom7.git

https://github.com/liwudi/react-router-dom8.git

使用方式:在根目录下npm install,用于下载依赖的包,然后npm start启动项目。

你可能感兴趣的:(React)