[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 ...
随机推荐
- C#面向对象的一些笔记
抽象 抽象类通常表示一个抽象的概念,提供一个继承的出发点.当设计抽下类时候,尽可能的拥有更多的相同代码,更少的数据. 抽象类.方法用abstract关键字修饰: 抽象成员不能是private. 抽象类 ...
- mysql UNIX时间戳与日期的相互转换
UNIX时间戳转换为日期用函数: FROM_UNIXTIME() select FROM_UNIXTIME(1156219870); 日期转换为UNIX时间戳用函数: UNIX_TIMESTAMP() ...
- sql用户权限
登录 1)右键根目录属性 点下面的sql server 和 windows 身份验证模式 2)安全性右键新建,选择登陆 去掉 那个"用户下次登陆是必须改密码" ,下面默认数据库改为 ...
- 在android中如何查看sqlite数据表结构,以及data文件打不开问题
1.root你的手机 2.cmd进入DOS界面,并且cd 转换目录到AndroidSDK\platform-tools中 3.输入adb shell 4.输入su,进入root权限,此时$变为#,输入 ...
- Menu之选项菜单
Android有三种形式的菜单:选项菜单(optionMenu).上下文菜单(ContextMenu).子菜单(subMenu).最常用的是选项菜单,该菜单在点击menu按键后会在对应的Activit ...
- Input File 表单上传按钮美化
HTML <div class="input-file-button"> 上传图片<input type="file" class=" ...
- 【Linux】 任务调度/计划 cron
实时查看日志: tail -f /var/log/cron 显示任务调度 bash#crontab -u username -l 编辑 bash#crontab -u username -e 内容: ...
- How To Learn English Very Fast
How do you learn English very fast? Every week, I get emails about this topic. Typically, someone ...
- Js自动截取字符串长度,添加省略号“……”
JavaScript字符串处理函数,根据定义的长度截取字符串,超出部分裁掉追加……,很多时候网页上显示的内容需要缩成“...”该方法用于处理字符串显示固定长度,超长部分用“...”代替: /**参数说 ...
- AtomicInteger小小的理解
这里仅仅是验证多线程环境下,AtomicInteger的安全性. 通过源码不难发现两点: 1.value属性是volatile修饰 2.使用了unsafe的CAS操作 通过上述两点,实现非阻塞同步(乐 ...