Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React: open link in a new tab

I am trying to make it so that when the user clicks my label, it opens up a new tab with the specified URL. It currently is not working. Any ideas what I am doing wrong or need to do in my method?

rerouteToGoogle= () => {
    return <Link to="google.com" />

}

<MediaQuery query="(min-width: 550px)">
  <div style={styles.alignText}>
  <Label color='green' basic onClick={this.rerouteToGoogle} >CSV</Label>
  </div>
</MediaQuery>
like image 881
lakeIn231 Avatar asked Dec 14 '22 12:12

lakeIn231


1 Answers

in your case rerouteToGoogle renders a Link component. I believe what you're trying to achieve is opening the new tab link on click, not rendering it. In this case just change your function to

rerouteToGoogle= () => window.open('www.google.com', "_blank")
like image 124
HiLuLiT Avatar answered Dec 21 '22 12:12

HiLuLiT