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. 在java代码中显示json字符串(怎么避免json字符串中双引号在java代码中显示)

    String log = "eyJvcmRlckluZm8iOnsiaWQiOjEwNzQwNCwib3JkZXJJZCI6MjczNjQyMSwicHJvZHVjdENvZGUiOjQ1N ...

  2. 查看oracle数据库下面的所有的表,执行某个sql脚本:

    查看oracle数据库下面的所有的表: select * from user_tables;//user为用户名 执行某个sql脚本: SQL>@e 文件名.sql

  3. UIWebView加载不了页面, 但在电脑的浏览器上可以打开

    经排查, 系因为URL中包含有中文, 所以无法加载页面, 解决方法如下: 将URL进行转码 NSString *urlStr =[[NSString stringWithFormat:@"h ...

  4. 单点登录CAS使用记(六):单点登出、单点注销

    单点登出基本上没有啥配置 直接在原来logout的时候,重定向到Cas-Server的logout方法 @RequestSecurity @RequestMapping(value = "l ...

  5. [转]链接分析算法之:主题敏感PageRank

    原文引自:http://blog.csdn.net/hguisu/article/details/8005192,感谢 前面的讨论提到.PageRank忽略了主题相关性,导致结果的相关性和主题性降低, ...

  6. 【转】Debug和Release区别

    VC下Debug和Release区别 最近写代码过程中,发现 Debug 下运行正常,Release 下就会出现问题,百思不得其解,而Release 下又无法进行调试,于是只能采用printf方式逐步 ...

  7. 解决Windows服务1053错误方法

    WCF使用MSMQ绑定寄宿在Windows服务上,但启动服务时出现1053错误 在网上搜索了N多解决方案,都是比较高深的扯到原理和系统bug等问题 看了看到最后也没有解决,最终我决定使用一个比较山寨的 ...

  8. Rand

    我看了下网上,是这样的:rand()随机产生一个数(0-65535),加上%后,就是对其它数求余,求余产生的数取决于求余的数.比如,rand()%20;意思是利用rand()的返回值(一个0-6553 ...

  9. ecshop有关real_ip()你发现的问题

    我这边有一个ECSHOP后台,有一个功能,在客户下订单时自动获取客户IP,用的是ECSHOP本身的real_ip函数,但这个函数存在一个问题,十个订单得到的IP,可能会有几个与CNZZ统计得到的不一样 ...

  10. MySQL 插入数据时,中文乱码???问题的解决

    在终端,mysql -u root -p 登录: show variables like 'character%'; 来查看当前数据库的相关编码集. client 为客户端使用的字符集. connec ...