【问题标题】:Open New Link with Card Click (ReactJS)使用卡片点击打开新链接 (ReactJS)
【发布时间】:2018-10-28 23:09:08
【问题描述】:

我正在为我的程序使用 ReactJS 卡片

import Card from 'material-ui/Card/Card';

当我按下卡片时,我想转到一个链接,例如 www.google.com。我该怎么做?

【问题讨论】:

    标签: reactjs onclick href material-ui


    【解决方案1】:
    routeTo(){
    window.open('http://www.google.com'); //This will open Google in a new 
      }
    }
    
    <Card className={classes.card} onClick={()=>this.routeTo()}>
          <CardActionArea>
            <CardContent>
              <Typography gutterBottom variant="h5" component="h2">
                Lizard
              </Typography>
              <Typography component="p">
                Lizards are a widespread group of squamate reptiles, with over 6,000
                species, ranging across all continents except Antarctica
              </Typography>
            </CardContent>
          </CardActionArea>
          <CardActions>
            <Button size="small" color="primary" onClick={() => alert("Share")}>
              Share
            </Button>
            <Button size="small" color="primary">
              Learn More
            </Button>
          </CardActions>
        </Card>
    

    【讨论】:

    • this.routeTo()}> // 函数 --routeTo(){ window.open('google.com'); //这将在新的 } 中打开 Google
    • 嗨,Saurabh!您能否详细说明此代码的作用,以便 OP 能够理解您的代码在做什么?
    【解决方案2】:

    使用

    <a href="https://www.google.com/">
    

    而不是Link 外部链接组件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-06
      相关资源
      最近更新 更多