[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 ...
随机推荐
- predis如何实现phpredis的pconnect方法
predis和phpredis都是redis的php客户端,区别可以看这里,这里不赘述. phpredis是php扩展,由C语言编写,诞生较早,很多PHPer都熟悉. predis是用PHP语言编写, ...
- 精通 Oracle+Python,第 4 部分:事务和大型对象
通过 Python 管理数据事务.处理大型对象 2010 年 3 月发布 事务包含一组 SQL 语句,这组 SQL 语句构成数据库中的一个逻辑操作,如转帐或信用卡支付操作.将 SQL 语句聚合到一个逻 ...
- 正确安装 django-socketio
直接使用 pip 安装,连 example project 都运行不了... 要正常使用,关键是要使用正确版本的依赖包 Django (1.5.5) django-socketio (0.3.2) g ...
- Quartz1.8.5例子(七)
/* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...
- BZOJ 4010 菜肴制作
Description 知名美食家小A被邀请至ATM 大酒店,为其品评菜肴. ATM酒店为小A准备了\(N\)道菜肴,酒店按照为菜肴预估的质量从高到低给予\(1\)到\(N\)的顺序编号,预估质量最高 ...
- [BZOJ - 2631] tree 【LCT】
题目链接:BZOJ - 2631 题目分析 LCT,像线段树区间乘,区间加那样打标记. 这道题我调了一下午. 提交之后TLE了,我一直以为是写错了导致了死循环. 于是一直在排查错误.直到.. 直到我看 ...
- 【技术贴】解决支付宝充值信用卡还款跳转到网上银行报错Error 404 - Not Found
声明 : 本文在 GFDL 1.2 下发布,本文出处光大银行信用卡 http://bbs.090989.com/forum-186-1.html http://androidgao.blogspot ...
- Web-Scale-IT 到底是啥?
Gartner 对 2015 年 10 大 IT 趋势的预测中有一个词条为:Web Scale IT.我们跟随 Matthias Ankli 来了解一下究竟什么是 Web Scale IT.本文译自 ...
- 注意android裁图的Intent action
现在很多开发者在裁图的时候还是使用com.android.camera.action.CROP 来调用 startActivity(). 这不是个好主意. 任何不是依android开头的Action ...
- wireshark设置抓服务器的包
wireshark设置抓服务器的包: