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. sqlyog使用注意事项

    在sqlyog中执行sql语句时,如果sql语句没有加limit 0,1000; sqlyog会自动查询从0开始的1000条,结果导致mysql慢查系统中显示的sql语句末尾加上了limit 0,10 ...

  2. c# 语句关键字

    1. yield 它表明一个方法,操作符或者get选择器里会出现迭代. 用yield return 同时返回每一个元素,  返回类型必须是IEnumerable, IEnumerable<T&g ...

  3. Windows系统创建硬链接文件

    源文件夹:E:\深海 创建新硬链接文件夹:D:\微云同步盘\719179409\4-工作资料\深海   打开命令提示符(管理员) 敲入以下命令:   创建成功后,进入目录 D:\微云同步盘\71917 ...

  4. PHP中的定界符格式

    <?php //nowdoc(单引号定界符) //ABC可以是任合内容,放在单引号中 $c=<<<'ABC' 这里可以是任合内容 我是历的苛夺基 本原则叶落归根在运 输费艰难田 ...

  5. explicit 关键字

    C++ explicit关键字用来修饰类的构造函数,表明该构造函数是显式的,既然有"显式"那么必然就有"隐式",那么什么是显示而什么又是隐式的呢? 如果c++类 ...

  6. securecrt简介

    SecureCRT是最常用的终端仿真程序,简单的说就是Windows下登录UNIX或Liunx服务器主机的软件,本文主要介绍SecureCRT的使用方法和技巧 VanDyke CRT 和 VanDyk ...

  7. QC 2.0为啥可以快充

    根据高通给出的数据,Quick Charge 2.0 A级标准规定的最大充电电流为3A,如果在5V的情况下,充电功率就为15W,因此充电速度要比最高支持10W的Quick Charge 1.0技术更快 ...

  8. 多线程09-Lock和Condition

    1.概念 Lock比传统线程模型中的synchronized方式更加面向对象,与生活中的锁类似,锁本身也应该是一个对象.两个线程执行的代码片段要实现同步互斥的效果,它们必须用同一个Lock对象. 2. ...

  9. JS浏览器关闭时清空cookie

    function addCookie(objName,objValue,objHours){    var str = objName + "=" + escape(objValu ...

  10. storm教程

    二.安装部署   一.storm伪分布式安装 (一)环境准备1.OS:debian 72.JDK 7.0 (二)安装zookeeper1.下载zookeeper并解压 wget http://mirr ...