博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Redux] Navigating with React Router <Link>
阅读量:5088 次
发布时间:2019-06-13

本文共 1613 字,大约阅读时间需要 5 分钟。

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 }) => (    
)export default Root;

(:filter) means: it might not exisits.

 

In Foot.js, displaying the filter link like this;

const Footer = () => (  

Show: {

" "}
All
{
", "}
Active
{
", "}
Completed

);

 

We want to change it little bit, so it would be more url friendly:

Show: {

" "}
All
{
", "}
Active
{
", "}
Completed

 

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} ) => (    
{children} );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:

//deleteexport 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.

 

转载于:https://www.cnblogs.com/Answer1215/p/5558977.html

你可能感兴趣的文章
Spring Cloud 入门教程(六): 用声明式REST客户端Feign调用远端HTTP服务
查看>>
Spring Cloud 入门教程(一): 服务注册
查看>>
【2.2】创建博客文章模型
查看>>
【3.1】Cookiecutter安装和使用
查看>>
【2.3】初始Django Shell
查看>>
Linux(Centos)之安装Redis及注意事项
查看>>
虚继承中的内存布局
查看>>
学习日记2:nginx配置文件
查看>>
iOS Cell异步图片加载优化,缓存机制详解
查看>>
第二章 基本数据结构
查看>>
(转)Unity3D移动平台动态读取外部文件全解析
查看>>
回顾与陈景润讨论歌德巴哈猜想的情景
查看>>
移动端 竖屏 (转)
查看>>
css text-align
查看>>
c语言章节4
查看>>
VC(VISUAL_C++)虚拟键VK值列表
查看>>
《风笛》-林白
查看>>
Android 网络请求框架Retrofit
查看>>
GeoServer手动发布本地Shapefile地图
查看>>
KMP之我见
查看>>