[Redux] Navigating with React Router <Link>
We will learn how to change the address bar using a component from React Router.
In Root.js:
We need to add a param to change the Route:
import React from 'react';
import {Provider} from 'react-redux';
import {Router, Route, browserHistory } from 'react-router';
import App from './App'; const Root = ({ store }) => (
<Provider store={store}>
<Router history={browserHistory}>
<Route path="/(:filter)" component={App}/>
</Router>
</Provider>
) export default Root;
(:filter) means: it might not exisits.
In Foot.js, displaying the filter link like this;
const Footer = () => (
<p>
Show:
{" "}
<FilterLink filter="SHOW_ALL">
All
</FilterLink>
{", "}
<FilterLink filter="SHOW_ACTIVE">
Active
</FilterLink>
{", "}
<FilterLink filter="SHOW_COMPLETED">
Completed
</FilterLink>
</p>
);
We want to change it little bit, so it would be more url friendly:
<p>
Show:
{" "}
<FilterLink filter="all">
All
</FilterLink>
{", "}
<FilterLink filter="active">
Active
</FilterLink>
{", "}
<FilterLink filter="completed">
Completed
</FilterLink>
</p>
In the FilterLink.js:
We rewrite the code by using <Link> from 'react-router':
import React from 'react';
import { Link } from 'react-router'; const FilterLink = ( {filter, children} ) => (
<Link
to={filter === 'all' ? '' : filter}
activeStyle={{
textDecoration: 'none',
color: black
}}
>
{children}
</Link>
); export default FilterLink;
If the filter is 'all', then just use default url.
If the link is actived, then use the activeStyle.
And we can delete the action creator for setVisibilityFilter in actions.js:
//delete
export const setVisibilityFilter = (filter) => ({
type: 'SET_VISIBILITY_FILTER',
filter,
});
Aslo delete the Link.js, it is not needed anymore, we use the Link component from react-router.
[Redux] Navigating with React Router <Link>的更多相关文章
- [Redux] Filtering Redux State with React Router Params
We will learn how adding React Router shifts the balance of responsibilities, and how the components ...
- [Redux] Adding React Router to the Project
We will learn how to add React Router to a Redux project and make it render our root component. Inst ...
- [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 ...
- 最新的chart 聊天功能( webpack2 + react + router + redux + scss + nodejs + express + mysql + es6/7)
请表明转载链接: 我是一个喜欢捣腾的人,没事总喜欢学点新东西,可能现在用不到,但是不保证下一刻用不到. 我一直从事的是依赖angular.js 的web开发,但是我怎么能一直用它呢?看看最近火的一塌糊 ...
- [React Router v4] Style a Link that is Active with NavLink
We often need to be able to apply style to navigation links based on the current route. In React Rou ...
- [React Router v4] Use the React Router v4 Link Component for Navigation Between Routes
If you’ve created several Routes within your application, you will also want to be able to navigate ...
- 关于react router 4 的小实践
详细代码栗子:https://github.com/wayaha/react-dom-CY clone然后 npm install npm start 分割线 1.这个项目使用create-react ...
- React Router 4.x 开发,这些雷区我们都帮你踩过了
前言 在前端框架层出不穷的今天,React 以其虚拟 DOM .组件化开发思想等特性迅速占据了主流位置,成为前端开发工程师热衷的 Javascript 库.作为 React 体系中的重要组成部分:Re ...
- React Router API文档
React Router API文档 一.<BrowserRouter> 使用HTML5历史记录API(pushState,replaceState和popstate事件)的<Rou ...
随机推荐
- web系统
现在的web系统已经越来越多的应用缓存技术,而且缓存技术确实是能实足的增强系统性能的.我在项目中也开始接触一些缓存的需求. 开始简单的就用jvm(java托管内存)来做缓存,这样对于单个应用服务器来说 ...
- linux 的一些 不常见的指标
1. linux 的理论 最大用户数 2^32 -1 数据来源 linux就是这个范 (没验证) 2. mv 竟然不能修改文件更新时间
- uboot环境变量初始化
一.环境变量概述 1.环境变量的概念 可以理解为用户对软件的全局配置信息,这部分信息应该可以从永久性存储器上读取,能被查询,能被修改. 启动过程中,应该首先把环境变量读取到合适的内存区域,然后利用环境 ...
- MFC窗口分割以及各窗口间的通讯
一个偶然的机会又重新接触了MFC窗口的分割,自己结合资料重新写了一个窗口分割的程序,现将具体流程跟大家分享一下: 1.我们先创建一个MFC单文档类的程序,具体分割方式先将单文档整个客户区分成两行一列, ...
- hadoop 2.x 安装包目录结构分析
bin:Hadoop最基本的管理脚本和使用脚本所在目录,这些脚本是sbin目录下管理脚本的基础实现,用户可以直接使用这些脚本管理和使用hadoop etc:Hadoop配置文件所在目录,包括core- ...
- [操作系统]iOS6与iOS7屏幕适配技巧
一.没有包装任何 导航控制器 或者 UITabBarController 1.控制器的view是UIScrollView\UITableView\UICollectionView时(控制器是UITab ...
- Dining
poj3281:http://poj.org/problem?id=3281 题意:有n个人,然后有F份食物,D份饮料,然后每一个会有一些喜爱的饮料和食物,问你最多可以使得多少人同时得到一份自己喜爱的 ...
- 深入了解一下PYTHON中关于SOCKETSERVER的模块-D
在LINUX上以FORK的方式使用SIMPLEHTTPSERVER. 记得哟,THREADING能在WIN和LINUX上实现,但FORK,不支持WIN的. 除了SIMPLE之外,还有CGI,就不示例啦 ...
- [wikioi]数字三角形
http://wikioi.com/problem/1220/ 最基本经典的DP题目,唯一有点意思的是,自底向上计算会更简洁.另外对这种+方式累计的DP,可以直接把原来的存进去,然后再加,本质是不用在 ...
- wcf托管在IIS上,提示未能加载
“/”应用程序中的服务器错误. 未能加载文件或程序集“ZBMYunCoreLib.DLL”或它的某一个依赖项.找不到指定的模块. 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈跟踪 ...