Cosmin Atanasiu
Cosmin Atanasiu

Reputation: 2654

How do I dispatch an action to reload the current route?

I'm using React with React Router and Redux. I want to be able to dispatch an action from a component, that ends up reloading the current route. Is this possible ?

I would use browserHistory.push but the problem with this is that I'd first have to know the current route inside the component, which I don't, at least not without adding some cumbersome hacks to the component.

Any help is highly appreciated!

Upvotes: 1

Views: 4859

Answers (2)

hellopath
hellopath

Reputation: 223

React-Router has a method to refresh/reload the page that you are currently. https://github.com/reactjs/react-router/blob/v0.13.3/modules/createRouter.js#L435-L437

Router.refresh()

You just need to call it from any part on your application. I don't think that you need to create an action for that.

Upvotes: 4

trquoccuong
trquoccuong

Reputation: 2873

inside a component you can use

this.context.router.push()

config before use

Component.contextTypes = {
    router: function () {
        return React.PropTypes.func.isRequired;
    }
};

Upvotes: -1

Related Questions