码迷,mamicode.com
首页 > 其他好文 > 详细

[Redux] Adding React Router to the Project

时间:2016-06-04 16:30:51      阅读:356      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/5558902.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!