본문 바로가기

FrontEnd/React

[FrontEnd]React Router And History

configureStore.js


import { createStore , combineReducers, applyMiddleware } from "redux"
import thunk from "redux-thunk"
import { routerReducer, routerMiddleware } from "react-router-redux";
import createHistory from "history/createBrowserHistory";
import users from './modules/users'

const env = process.env.NODE_ENV;

const history = createHistory()

const middlewares = [thunk,routerMiddleware(history)];

if(env === "development"){
const { logger } = require("redux-logger");
middlewares.push(logger);
}

const reducer = combineReducers({
users,
routing : routerReducer
});

let store = initialState =>
createStore(reducer, applyMiddleware(...middlewares));

export { history };

export default store();


index.js


import React from 'react';
import ReactDOM from 'react-dom';
import {Provider} from "react-redux";
import { ConnectedRouter } from "react-router-redux";
import store, { history } from "./redux/configureStore";
import './index.css';
import App from './App';

ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>
</Provider>
, document.getElementById('root'));


console.log



'FrontEnd > React' 카테고리의 다른 글

[FrontEnd]redux devtools 정의 및 설치  (0) 2018.11.17
[FrontEnd]Reactotron 정의 및 설치  (0) 2018.11.17
[FrontEnd]React-Router  (0) 2018.11.14
[FrontEnd]미들웨어 Redux logger  (0) 2018.11.13
[FrontEnd]미들웨어 Redux Thunk  (0) 2018.11.13