react onclick 跳转路由
import { withRouter } from ‘react-router-dom’
render() {
const push= (e,v)=>{
// let url= v.userUrl ? v.userUrl : "/user/"+v.username
// this.push(url)
// push
// e.target.value
let url= v.userUrl ? v.userUrl : "/user/"+v.username
console.log("url");
console.log(url);
console.log( "this.props");
console.log( this.props);
this.props.history.push(url)
}
return (
this.state.user.map(function (v,i) {
return (
<div className="article-item" key={i}>
<div className="doc style-small-image style-content-middle item-0 "
onClick={
(event)=>push(event,v)
}
// to={v.userUrl ? v.userUrl : "/user/"+v.username}
>
export default withRouter(Theme); // export时要使用withRouter