Reputation: 2654
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
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
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