利用 react-router的withRouter进行 js 控制路由跳转
import React,{Component} from 'react';
import { withRouter } from 'react-router';
@withRouter
export default myComponent extends Component {
constructor(props){
super(props)
}
routerChange(){
const { history } = this.props;
history.push('你要跳转的路由')
}
render(){
return(
<div>
<button
onClick={
this.routerChange.bind(this)
}
>
点我跳转
</button>
</div>
)
}
}
PS:上述代码使用了 babel 装饰器方法,相关配置方法请点击下方链接
网友评论