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的更多相关文章

  1. [React] React Router: Querystring Parameters

    Define query param in Link, accept path and query : const Links = () => <nav > <Link to= ...

  2. [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 ...

  3. [React] React Router: Redirect

    The Redirect component in react-router does exactly what it sounds like. It allows us to redirect fr ...

  4. [React] React Router: Named Components

    In this lesson we'll learn how to render multiple component children from a single route. Define a n ...

  5. [React] React Router: IndexRoute

    IndexRoute allows us to define a default child component to be rendered at a specific route when no ...

  6. [React] React Router: Nested Routes

    Since react-router routes are components, creating nested routes is as simple as making one route a ...

  7. React+React Router+React-Transition-Group实现页面左右滑动+滚动位置记忆

    2018年12月17日更新: 修复在qq浏览器下执行pop跳转时页面错位问题 本文的代码已封装为npm包发布:react-slide-animation-router 在React Router中,想 ...

  8. ReactJS React+Redux+Router+antDesign通用高效率开发模板,夜间模式为例

    工作比较忙,一直没有时间总结下最近学习的一些东西,为了方便前端开发,我使用React+Redux+Router+antDesign总结了一个通用的模板,这个技术栈在前端开发者中是非常常见的. 总的来说 ...

  9. Nginx支持 React browser router

    修改nginx配置文件,添加try_file配置如下,即可实现对 React browser router 的支持. location / { root /var/www/mysite; try_fi ...

随机推荐

  1. sourceTree添加git密钥步骤

    给多个远程服务器比如https://github.com/wangjian2014/wjtest/blob/master/wj.txt添加public密钥 本地服务器添加private密钥     S ...

  2. ant打包命令

    学习ant打包命令.发布到以上tomcat还未做集成部署,无法添加到jenkins中. http://blog.csdn.net/telnetor/article/details/7015935 ht ...

  3. Win7上IIS发布网站系统\部署项目

    1.系统已经安装IIS,如果没有安装,请到[控制面板]→[程序]→[程序和功能]→[打开或关闭Windows功能],选中Internet 信息服务Web管理工具下面的所有选项,确定:如下图 2.发布文 ...

  4. this computer does not support Intel Virtualization Technology (VT-x) .Haxm can'not be installed

    this computer does not support Intel Virtualization Technology (VT-x) .Haxm can'not be installed 本机不 ...

  5. Linux系统文本命令快速登录与退出

    Linux是一个多用户的操作系统,用户要使用该系统,首先必须登录系统,使用完系统后,必须退出系统.用户登录系统时,为了使系统能够识别自己,必须输入用户名和密码,经系统验证无误后方能进入系统.在系统安装 ...

  6. maven实现tomcat热部署

    1.使用maven+tomcat事项热部署 1.1修改tomcat-user.xml <role rolename="manager-gui"/> <!--man ...

  7. 武汉科技大学ACM:1005: 单位转换

    Problem Description BobLee最近在复习考研,在复习计算 机组成原理的时候,遇到了一个问题.就是在计算机存储里面的单位转换.我们都知道1MB=1024KB,1KB=1024B,1 ...

  8. 研究一下uucode编码

    uucode编码是把任意二进制数据转换为ascii字符的编码用于在一些只能传递文本的地方传送二进制数据uu模块提供了encode()和decode()用于将一个文件转换为uucode编码的字符文件,文 ...

  9. CentOS+nginx+uwsgi+Python 多站点环境搭建

    转载:http://www.cnblogs.com/xiongpq/p/3381069.html 环境: CentOS X64 6.5 nginx 1.5.6 Python 2.7.5 正文: 一:安 ...

  10. zabbix log(logrt) key的使用

    今天看了篇帖子是关于如何利用zabbix 自带的key去读log,监控linux异常登陆,一直以来都是自己写脚本去读log的.就想看看这个zabbix log 这个key怎么样..好吧开始: 官方文档 ...