Skip to content

Best practice to redirect within action creator? #3498

@olalonde

Description

@olalonde

There seems to be two ways to redirect from an action creator (react-redux):

  1. Use withRouter() on component which calls the action creator and pass props.router to the action creator (e.g. dispatch(login(username, password, this.props.router)) and router.push('/success') inside my action creator)

  2. import { browserHistory } from 'react-router' inside the action creator file and browserHistory.push('/success') as mentioned here: https://github.com/reactjs/react-router/blob/master/docs/guides/NavigatingOutsideOfComponents.md

I was wondering which one would be preferable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions