Navigating with React router without using links

时间:2016-07-11 18:57:37

标签: reactjs frontend react-router

I'm using react-router to build a simple application. I can't use browserHistory approach, so, I'm using the hashHistory approach. However, I'm stucked in a point. How can I do a function 'clickHandler' for a submit form, in order to land on another route?

Here is a snippet:

onSubmit: function() {
    //go to some route here...
},
render: function() {
    return(
        <button onClick={this.onSubmit} >Submit</button>
   )
}

thanks

1 个答案:

答案 0 :(得分:4)

Can you try the following:

import { hashHistory } from 'react-router';

onSubmit: function() {
   hashHistory.push('/foo');
},

You can see the full history API here: https://github.com/ReactJSTraining/history