文当上的路由跳转是点击标签实现的,那怎么用函数的方式就行路由跳转呢?
查了个方法import createHistory from 'history/createBrowserHistory'
然后用history.push(’/About’)就行路由跳转,但是地址栏的路径虽然变化了呢,对应的路由模块却没有发生变化
文当上的路由跳转是点击标签实现的,那怎么用函数的方式就行路由跳转呢?
查了个方法import createHistory from 'history/createBrowserHistory'
然后用history.push(’/About’)就行路由跳转,但是地址栏的路径虽然变化了呢,对应的路由模块却没有发生变化
你可以使用
import { withRouter } from 'react-router-dom'
@withRouter
class App extends React.Component{
linkTo(){
this.props.history.push('/xxxx')
}
}
import {hashHistory} from 'react-router'
;
const App = () => (
<div>
<input type="button" value="test" onClick={() => {hashHistory.push('/user/reg')}} />
</div>
)