想实现点击Paper组件,跳转到一个新的链接,可以使用Link和Redirect,不能用a标签,会导致全局重新加载。handleVideoClick方法已经能识别出点击了哪一个Paper,但是不知道怎么写跳转的逻辑。因为不能在非render中渲染视图,所以不知道怎么做。importReactfrom'react';importPropTypesfrom'prop-types';import{withStyles,createStyleSheet}from'material-ui/styles';import{Link,Redirect}from'react-router-dom';importPaperfrom'material-ui/Paper';importTypographyfrom'material-ui/Typography';importreptileImagefrom'../images/bg.jpg';conststyleSheet=createStyleSheet('VideoList',{card:{maxWidth:"98%",margin:"0auto",},});classVideoListextendsReact.Component{constructor(props){super(props);}handleVideoClick(videoId,event){event.preventDefault();console.log(videoId);}render(){constclasses=this.props.classes;return(LizardLizardsareawidespreadgroupofsquamatereptiles,withover6,000species,rangingacrossallcontinentsexceptAntarcticaLizardLizardsareawidespreadgroupofsquamatereptiles,withover6,000species,rangingacrossallcontinentsexceptAntarctica);}}VideoList.propTypes={classes:PropTypes.object.isRequired,};exportdefaultwithStyles(styleSheet)(VideoList);
2 回答
智慧大石
TA贡献1946条经验 获得超3个赞
react-router里不是有个hashHistorybrowserHistory两个方法??browserHistory.push();hastHistory.push();都可以跳转啊
添加回答
举报
0/150
提交
取消