when u seem to require forward in reactjs we used to put a Link or button ,and then consumer click it ,then the page reload corresponding path of router . Now,I want the page turn to other path of router when I request a post and the status of response is 200. It can't use a link or button ,could reactjs use code to do this? like : CertainComponent.setPath(otherPath); CertainComponent.turn; My English is poor , it may be not clear to delive the function which i want to do. Thanks!
Asked
Active
Viewed 42 times
2 Answers
0
I think you want to use this.context.router.push('/users/12')
https://github.com/reactjs/react-router/blob/master/docs/API.md#routercontext
![](../../users/profiles/4195140.webp)
DeBug
- 19
- 4
0
First of all the component you are using has to be a container, which means you have to create it with connect() so it has access on store and dispatch:
let MyComponent = ({ dispatch, store }) => {
store.routing.push('url');
}
export default connect()(MyComponent)
And this depends how you named the router key on your store when you combined the routing reducer from redux-router on your store.
There is also another alternative, where you could do
import { hashHistory } from 'react-router';
hashHistory.push('next-url');
![](../../users/profiles/497255.webp)
Rosmarine Popcorn
- 10,242
- 11
- 53
- 87
-
yes ,i have solved this problem ,and i find that i can import hashHistory everywhere and use it(our corporation use redux ,i use it in action). Thank for your help ! – page xu Jun 25 '16 at 17:55