[React] React Router: Route Parameters
A router library is no good if we have to hardcode every single route in our application. In this lesson we look at how to access variables in our routes and pass them into our components.
Define a route param by using ":message", () make it optional:
<Route path="/(:message)" component={Home}></Route>
Get route param:
const Home = (props) => <div><h1>{props.params.message ||'hello'}</h1><Links></Links></div>;
---------------
import React from 'react';
import {hashHistory, Route, Router, Link, IndexRoute} from 'react-router'; const Home = (props) => <div><h1>{props.params.message ||'hello'}</h1><Links></Links></div>; const Links = () =>
<nav >
<Link to="/">Home</Link>
<Link to="/foo">Foo</Link>
<Link to="/bar">Bar</Link>
</nav>; class App extends React.Component {
render(){
return(
<Router history={hashHistory}>
<Route path="/(:message)" component={Home}></Route>
</Router>
);
}
} export default App;
[React] React Router: Route Parameters的更多相关文章
- [React] React Router: Querystring Parameters
Define query param in Link, accept path and query : const Links = () => <nav > <Link to= ...
- [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] React Router: Redirect
The Redirect component in react-router does exactly what it sounds like. It allows us to redirect fr ...
- [React] React Router: Named Components
In this lesson we'll learn how to render multiple component children from a single route. Define a n ...
- [React] React Router: IndexRoute
IndexRoute allows us to define a default child component to be rendered at a specific route when no ...
- [React] React Router: Nested Routes
Since react-router routes are components, creating nested routes is as simple as making one route a ...
- React+React Router+React-Transition-Group实现页面左右滑动+滚动位置记忆
2018年12月17日更新: 修复在qq浏览器下执行pop跳转时页面错位问题 本文的代码已封装为npm包发布:react-slide-animation-router 在React Router中,想 ...
- ReactJS React+Redux+Router+antDesign通用高效率开发模板,夜间模式为例
工作比较忙,一直没有时间总结下最近学习的一些东西,为了方便前端开发,我使用React+Redux+Router+antDesign总结了一个通用的模板,这个技术栈在前端开发者中是非常常见的. 总的来说 ...
- Nginx支持 React browser router
修改nginx配置文件,添加try_file配置如下,即可实现对 React browser router 的支持. location / { root /var/www/mysite; try_fi ...
随机推荐
- python面对对象编程------3:写集合类的三种方法
写一个集合类的三种方法:wrap,extend,invent 一:包装一个集合类 class Deck: def __init__( self ): self._cards = [card6(r+1, ...
- Eclipse 运行ant build.xml
在命令行cmd运行mvn clean install,ant compiler,提示上述信息,是因为 maven的这个插件要求jdk1.6,但是本地电脑环境变量jdk版本为1.7.将JAVA_HOME ...
- 使用VS2012的C++生成dll
1,首先,通过File->New Project的方式新建一个工程,打开"New Project"对话框. 2,选择Visual C++语言下的 Win32->Win3 ...
- BitmapImage使用FileStream读取文件
var bitmapImage = new BitmapImage(); using (FileStream fs = new FileStream(file.FullName, FileMode.O ...
- mssql 查询全部用户创建表 条数及占用空间大小(KB)
select b.name as tablename , --表名a.rowcnt as datacount, --条数rtrim(8*a.dpages) as size --占用空间单位KBf ...
- angularjs使用directive实现分页组件
闲来没事,分享下项目中自己写的分页组件.来不及了,直接上车. 效果: 输入框可任意输入,并会自动提交到该页 html: <ul class="page clearfix"&g ...
- wm_char
用于接收键盘输入的消息 int CXuexi2View::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateS ...
- phpEXCEL操作全解
phpExcel中文帮助手册,列举了各种属性,以及常用的操作方法,难得是每一个都用实例加以说明,希望对大家有所帮助. phpExcel中文帮助手册,不可多得的好文章,供大家学习参考. 1.设置exce ...
- VS2010安装项目的系统必备中添加.NET 2.0
把DotNetFX.rar解压后的DotNetFX文件夹,放置于安装了 VS2010 的 C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bootstrap ...
- [LeetCode 119] - 杨辉三角形II(Pascal's Triangle II)
问题 给出一个索引k,返回杨辉三角形的第k行. 例如,给出k = 3,返回[1, 3, 3, 1] 注意: 你可以优化你的算法使之只使用O(k)的额外空间吗? 初始思路 首先来复习复习杨辉三角形的性质 ...