React Router的Route的使用
Route 是 React Router中用于配置路由信息的组件,每当有一个组件需要根据 URL 决定是否渲染时,就需要创建一个 Route。
1) path
每个 Route 都需要定义一个 path 属性,path 属性是一个url,当 URL 匹配一个 Route 时,这个 Route 中定义的组件就会被渲染出来。
2)Route 渲染组件的方式
(1)component
component 的值是一个组件,当 URL 和 Route 匹配时,Component属性定义的组件就会被渲染。例如:
<Route path='/foo' component={Foo} >
当 URL = "http://example.com/foo" 时,Foo组件会被渲染。
(2) render
render 的值是一个函数,这个函数返回一个 React 元素。这种方式方便地为待渲染的组件传递额外的属性。例如:
<Route path='/foo' render={(props) => {
 <Foo {...props} data={extraProps} />
}}>
</Route>
Foo 组件接收了一个额外的 data 属性。
(3)children
children 的值也是一个函数,函数返回要渲染的 React 元素。 与前两种方式不同之处是,无论是否匹配成功, children 返回的组件都会被渲染。但是,当匹配不成功时,match 属性为 null。例如:
<Route path='/foo' render={(props) => {
 <div className={props.match ? 'active': ''}>
  <Foo {...props} data={extraProps} />
 </div>
}}>
</Route> 
如果 Route 匹配当前 URL,待渲染元素的根节点 div 的 class 将设置成 active.
React Router的Route的使用的更多相关文章
- [React] React Router: Route Parameters
		A router library is no good if we have to hardcode every single route in our application. In this le ... 
- [React] React Router: Router, Route, and Link
		In this lesson we'll take our first look at the most common components available to us in react-rout ... 
- 【react router路由】<Router> <Siwtch> <Route>标签
		博客 https://www.jianshu.com/p/ed5e56994f13?from=timeline 文档 http://react-guide.github.io/react-router ... 
- [React Router v4] Intercept Route Changes
		If a user has entered some input, or the current Route is in a “dirty” state and we want to confirm ... 
- [React Router v4] Render Multiple Components for the Same Route
		React Router v4 allows us to render Routes as components wherever we like in our components. This ca ... 
- [React Router v4] Conditionally Render a Route with the Switch Component
		We often want to render a Route conditionally within our application. In React Router v4, the Route ... 
- [转] React Router 使用教程
		PS:react-route就是一个决定生成什么父子关系的组件,一般和layout结合起来,保证layout不行,内部的子html进行跳转 你会发现,它不是一个库,也不是一个框架,而是一个庞大的体系. ... 
- [Redux] Navigating with React Router <Link>
		We will learn how to change the address bar using a component from React Router. In Root.js: We need ... 
- [Redux] Adding React Router to the Project
		We will learn how to add React Router to a Redux project and make it render our root component. Inst ... 
随机推荐
- ORACLE 数据库使用正则表达式重新计算指定位置的数字为新的数字
			昨天工作中遇到这个问题: 有一个这样的字符串expression变量,里面可能存储的值类似于以下[Index_CivilWork,0]*(1+[Y10814,1])/[Y10674,1] [300,1 ... 
- C/C++程序中内存被非法改写的一个检测方法
			本文所讨论的“内存”主要指(静态)数据区.堆区和栈区空间(详细的布局和描述参考<Linux虚拟地址空间布局>一文).数据区内存在程序编译时分配,该内存的生存期为程序的整个运行期间,如全局变 ... 
- python科学计算包numpy用法(一)
			numpy是python中一个用来做科学计算的包,用起来十分方便,下面是我总结的numpy的用法: 1.如何创建矩阵 创建矩阵有很多种方法,主要包括以下几种: 通过array函数创建 >> ... 
- Excel 2016 密码保护破解
			Excel 2016的密码保护可以区分为几个: 文件密码保护(Excel中叫做工作簿保护) 文件打开权限密码 文件修改权限密码 工作表保护 关于各个保护密码的设置方式请查阅其他资料,我的情况是之前自己 ... 
- 安装Git Bash图文教程
			1.下载Git Bash,下载地址 https://pan.baidu.com/s/1sllsi0d 2.双击Git-2.9.2-64-bit.exe,运行,进行安装:点击“Next” 3.设置安装路 ... 
- redis读书笔记
			1.redis两种存储机制(持久化) Redis的存储机制分为:Snapshot和AOF 都先将内存存储在内存中. (1)Snapshot当数据累计到一定的阈值,就会触发dump将数据一次性写入到数据 ... 
- vue 组件自定义v-model
			参考资料:vue官网在vue 中使用v-model双向绑定 <input v-model="something"> 其实是语法糖 <input :value=&q ... 
- LeetCode  237. Delete Node in a Linked List 删除链表结点(只给定要删除的结点) C++/Java
			Write a function to delete a node (except the tail) in a singly linked list, given only access to th ... 
- 20164304姜奥——Exp1 PC平台逆向破解
			1.1 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符串. 该程序同时包含另一个代码片段,ge ... 
- 使用samba  共享Linux文件到Windows
			1.使用yum命令安装了samba服务 #yum install samba 2.配置/etc/samba/smb.conf文件,在最后一行添加下面一段配置: #vi /etc/samba/smb.c ... 
