在不使用链接的情况下使用 React 路由器导航
Navigating with React router without using links
我正在使用 react-router 构建一个简单的应用程序。我不能使用 browserHistory 方法,所以,我使用的是 hashHistory 方法。但是,我陷入了困境。我如何为提交表单执行函数 'clickHandler',以便登陆另一条路线?
这是一个片段:
onSubmit: function() {
//go to some route here...
},
render: function() {
return(
<button onClick={this.onSubmit} >Submit</button>
)
}
谢谢
你可以尝试以下方法吗:
import { hashHistory } from 'react-router';
onSubmit: function() {
hashHistory.push('/foo');
},
您可以在此处查看完整的 history
API:
https://github.com/ReactJSTraining/history
我正在使用 react-router 构建一个简单的应用程序。我不能使用 browserHistory 方法,所以,我使用的是 hashHistory 方法。但是,我陷入了困境。我如何为提交表单执行函数 'clickHandler',以便登陆另一条路线?
这是一个片段:
onSubmit: function() {
//go to some route here...
},
render: function() {
return(
<button onClick={this.onSubmit} >Submit</button>
)
}
谢谢
你可以尝试以下方法吗:
import { hashHistory } from 'react-router';
onSubmit: function() {
hashHistory.push('/foo');
},
您可以在此处查看完整的 history
API:
https://github.com/ReactJSTraining/history