0

My index.js looks like:

const store = configureStore()

render(
    <Root history={history} store={store} />,
  document.getElementById('root')
)

and my Root.js looks like:

class Root extends Component {
  render() {
    const { store } = this.props

    return (
      <Provider store={store}>
          <ReduxRouter />
      </Provider>
    )
  }
}

Root.propTypes = {
  store: PropTypes.object.isRequired,
  history: PropTypes.object
}

export default Root

and my configureStore.js is like:

export default function configureStore() {

  let createStoreWithMiddleware = compose(
    applyMiddleware(thunk),
    reduxReactRouter({ routes, createHistory })
    )(createStore)

  const store = createStoreWithMiddleware(rootReducer)

  return store

routes.js:

const routes =  (
    <Router>
        <Route path={"/"} component={LoginView}>
        <Route path={"/login"} component={DashboardView} />
        </Route>
  </Router>
)

export default routes

and my LoginView component is like:

class LoginView extends Component {

    componentDidMount(){
        const {actions} = this.props
        actions.login()
    }

    render() {
        console.log("printing props")
        console.log(this.props)
        console.log(this.props.history)
        return (
            <div>
                <Login />
            </div>
        )
    }
}

export default LoginView


function mapStateToProps(state) {
    return {
        login: state.login
    }
}

function mapDispatchToProps(dispatch) {
  return {
    actions: bindActionCreators(Actions, dispatch)
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(LoginView)

I am very confused relating to history. In my component I am getting history in props. Like this.props.history as I have done console.log(this.props.history) in component.

But in my actions I can not get history any way..

My actions is like:

export function login(){

    return (dispatch, getState, history) => {
        console.log("get state")
        console.log(getState())
        console.log("history")
        console.log(history)
        var message = "hellooww world"
        return { message, type: loginTypes.LOGIN }
    }
}

Here I can get getState() but not history.

What If I want to redirect? I want history so that I can redirect it like:

history.pushState(null, '/dashboard')

Can anyone help me.. ? Really confused on this..

varad
  • 5,407
  • 14
  • 45
  • 95

1 Answers1

0

Well I found this GitHub page offering a simple way of transitioning from an action, maybe it will help (it has an example of a login action):

https://github.com/johanneslumpe/redux-history-transitions

Theo
  • 955
  • 7
  • 14