We will learn how to add React Router to a Redux project and make it render our root component.

Install:

npm install --save react-router
import React from 'react';
import {Provider} from 'react-redux';
import {Router, Route} from 'react-router';
import App from './App'; const Root = ({ store }) => (
<Provider store={store}>
<Router>
<Route path="/" component={App}/>
</Router>
</Provider>
) export default Root;

Router should be wrapped inside Provider, then all the children components can access the router.

Currentlly when we open the browser, we saw the url is like:

http://localhost:3000/#/?_k=k4ctzs

To fix this need to import 'browserHistry':

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="/" component={App}/>
</Router>
</Provider>
) export default Root;

[Redux] Adding React Router to the Project的更多相关文章

  1. [Redux] Filtering Redux State with React Router Params

    We will learn how adding React Router shifts the balance of responsibilities, and how the components ...

  2. 最新的chart 聊天功能( webpack2 + react + router + redux + scss + nodejs + express + mysql + es6/7)

    请表明转载链接: 我是一个喜欢捣腾的人,没事总喜欢学点新东西,可能现在用不到,但是不保证下一刻用不到. 我一直从事的是依赖angular.js 的web开发,但是我怎么能一直用它呢?看看最近火的一塌糊 ...

  3. [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 ...

  4. 关于react router 4 的小实践

    详细代码栗子:https://github.com/wayaha/react-dom-CY clone然后 npm install npm start 分割线 1.这个项目使用create-react ...

  5. React Router 4.x 开发,这些雷区我们都帮你踩过了

    前言 在前端框架层出不穷的今天,React 以其虚拟 DOM .组件化开发思想等特性迅速占据了主流位置,成为前端开发工程师热衷的 Javascript 库.作为 React 体系中的重要组成部分:Re ...

  6. React Router API文档

    React Router API文档 一.<BrowserRouter> 使用HTML5历史记录API(pushState,replaceState和popstate事件)的<Rou ...

  7. [Web 前端] React Router v4 入坑指南

    cp from : https://www.jianshu.com/p/6a45e2dfc9d9 万恶的根源 距离React Router v4 正式发布也已经过去三个月了,这周把一个React的架子 ...

  8. React Router V4发布

    React Router V4 正式版发布,该版本相较于前面三个版本有根本性变化,遵循 Just Component 的 API 设计理念. 本次升级的主要变更有: 声明式 Declarative 可 ...

  9. React躬行记(13)——React Router

    在网络工程中,路由能保证信息从源地址传输到正确地目的地址,避免在互联网中迷失方向.而前端应用中的路由,其功能与之类似,也是保证信息的准确性,只不过来源变成URL,目的地变成HTML页面. 在传统的前端 ...

随机推荐

  1. 博客系统-3.0CodeIgniter系统SAE版本的配置 application/config/

    autoload.php(系统启动时自动加载的文件:包,类库,驱动,方法助手,配置) $autoload['libraries'] = array('database', 'access', 'pag ...

  2. 帝国cms7.0修改默认搜索模版中的分页[!--show.page--]

    修改默认搜索模版的分页是在e/class/connect.php下 搜索下function page1就是我们要修改的分页了 下面贴上我修改后的分页 //前台分页 function page1($nu ...

  3. js 图片base64

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...

  4. MAC Python环境配置以及安装Pycharm 5.4.0

    安装XCODE 去APP STORE下载,然后安装.免费 终端执行 xcode-select --install 安装或更新命令行开发工具 安装Pycharm 下载软件 官网:https://www. ...

  5. DBA - 我的学习

    DBA - 我的学习 1. df -k 检查oracle 分区硬盘使用情况 2. 检查alert_<SID名称>.log, alert日志文件,检查是否新增错误日志 3. 检查数据文件的状 ...

  6. POJ Code the Tree 树的pufer编号

    Code the Tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2259   Accepted: 859 Desc ...

  7. uva 10130 SuperSale

    一个01背包问题: 刚刚开始把题目看错了,以为物品的数目是有限的,然后让你求一个家庭里最多能够拿多个价值的东西: 这样一来的话,这个题目就有点意思了: 但是后来发现竟然是个简单的01背包问题 =  = ...

  8. spring 动态数据源

    1.动态数据源:  在一个项目中,有时候需要用到多个数据库,比如读写分离,数据库的分布式存储等等,这时我们要在项目中配置多个数据库. 2.原理:   (1).spring 单数据源获取数据连接过程: ...

  9. lc面试准备:Power of Two

    1 题目 Given an integer, write a function to determine if it is a power of two. 接口 boolean isPowerOfTw ...

  10. HDU 1150 Machine Schedule

    题目大意: 有两台机器A和B以及K个需要运行的任务.A机器有N种不同的模式,B机器有M种不同的模式,而每个任务都恰好在一台机器上运行. 如果它在机器A上运行,则机器A需要设置为模式xi,如果它在机器B ...