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启动项目。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值