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

来源:互联网 发布:淘宝直播怎么开 编辑:程序博客网 时间:2024/06/06 05:10

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也会展示出来。
  • 1
  • 2
  • 3

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

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

2、下面是八个react路由示例:(github上面)。
git@github.com:liwudi/react-router-demo1.git

git@github.com:liwudi/react-router-demo2.git

git@github.com:liwudi/react-router-demo3.git

git@github.com:liwudi/react-router-demo4.git

git@github.com:liwudi/react-router-demo5.git

git@github.com:liwudi/react-router-demo6.git

git@github.com:liwudi/react-router-demo7.git

git@github.com:liwudi/react-router-demo8.git

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

原创粉丝点击