[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 ...
随机推荐
- bash:ifconfig command not found for contos7.0
CentOS7刚发布,我忍不住把DELL T410从CentOS6升级到CentOS7.好不容易等安装结束后,立即配置网络,然后在yum源上安装环境.可是执行ifconfig的时候系统提示让我傻了眼: ...
- Windows 7 64位下解决不能创建Django项目问题
把djingo-admin.py的全路径写出来 在cmd命令行下直接输入python C:\Python27\Scripts\django-admin.py startproject site(sit ...
- zabbix log(logrt) key的使用
今天看了篇帖子是关于如何利用zabbix 自带的key去读log,监控linux异常登陆,一直以来都是自己写脚本去读log的.就想看看这个zabbix log 这个key怎么样..好吧开始: 官方文档 ...
- jQuery上传插件Uploadify 3.2使用
Uploadify下载地址:http://www.uploadify.com/download/ 这里下载最新版的3.2的. 常用API描述: $(document).ready(function() ...
- CSS样式鼠标点击与经过的效果一样
a:link /* 未访问的链接 */ a:visited /* 已访问的链接 */ a:hover /* 当有鼠标悬停在链接上 */ a:active /* 被选择的链接 */ a,a:visite ...
- 在PHP中获取日期和时间
PHP提供了多种获取时间和日期的函数,除了通过time()函数获取当前的UNIX时间戳外,调用getdate()函数确定当前时间,通过gettimeofday()函数获取某一天中的具体时间.此外,在P ...
- 字符串匹配算法之Sunday算法
字符串匹配查找算法中,最着名的两个是KMP算法(Knuth-Morris-Pratt)和BM算法(Boyer-Moore).两个算法在最坏情况下均具有线性的查找时间.但是在实用上,KMP算法并不比最简 ...
- pip安装第三方库以及版本
这篇blog只是写给自己看看的. 今天突然遇到sqlalchemy映射到数据库时,一个字段类型是datetime(6),我这边死活访问不上,之前一直没有问题,最后查明原因,原来是第三方库的版本问题,真 ...
- 转:Keil MDK从未有过的详细使用讲解
来自:http://blog.csdn.net/zhzht19861011/article/details/5846510 熟悉Keil C 51的朋友对于Keil MDK上手应该比较容易,毕竟界面是 ...
- Qt 错误汇集贴
错误: D:\qtprojects\mycom\mycom\mainwindow.cpp:23: error: no matching function for call to 'MainWindow ...