简体   繁体   中英

How do I go to an external link when I click on a button in next js

<button type="button" className = {styles.googleButton}>
     <img className = {styles.image} src = "assets/pictures/google.jpg"></img>
     <p className = {styles.buttonText}> Go To Google</p>
     <img src = "assets\icons\external-link.svg"></img>
</button>

when i click on this button how do i go to google.com on A DIFFERENT TAB?

Put it inside a href with a blank tab like

<a href="https://www.google.com" target="_blank">
<img src = "assets\icons\external-link.svg"></img>
</a>

Add an 'a' tag and set its target value to '_blank'. Also add "rel='noreferrer'".

Here is an example. It's working for me in my Nextjs project:

  <a href='https://www.google.com' target='_blank' rel='noreferrer'>
    <button type='button'>
      <img src='assets/pictures/google.jpg'></img>
      <p> Go To Google</p>
      <img></img>
    </button>
  </a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM