Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
Why does my React button no longer link to an external site using anchor tags?

I created a few buttons for my site in react. I used an anchor tag and everything was working fine but for some reason they no longer work. I don't remember making any changes and am confused as to why it stopped. Here's the button imported and used in the "About.js" file.

<Button text="Join Our Discord" link="https://discord.gg/Zrk8kXfs" />

And here is the where I created the button in "Button.js".

import React from "react";
import styled from "styled-components";

const Btn = styled.button`
  display: inline-block;
  background-color: ${(props) => props.theme.text};
  color: ${(props) => props.theme.body};
  outline: none;
  border: none;

  font-size: ${(props) => props.theme.fontsm};
  padding: 0.9rem 2.3rem;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;

  &:hover {
    transform: scale(0.9);
  }

  &::after {
    content: " ";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    border: 2px solid ${(props) => props.theme.text};
    width: 100%;
    height: 100%;
    border-radius: 50px;
    transition: all 0.2s ease;
  }

  &:hover::after {
    transform: translate(-50%, -50%) scale(1);
    padding: 0.3rem;
  }
`;

const Button = ({ text, link }) => {
  return (
    <Btn>
      <a href={link} aria-label={text} target="_blank" rel="noreferrer">
        {text}
      </a>
    </Btn>
  );
};

export default Button;

Any help would be greatly appreciated.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Try using "Link" feature from react-router-dom, first, npm i react-router-dom

import { Link } from "react-router-dom";

<Link to="https://discord.gg/Zrk8kXfs">
  <Button>Join Our Discord</Button>
</Link>
about 4 years ago · Juan Pablo Isaza Report

0

To use a button as a link in React, wrap the button in an <a> tag or a Link component if using react router. The button will get rendered instead of the link and clicking on it will cause the browser to navigate to the specified page. App.js

https://bobbyhadz.com/blog/react-button-link#:~:text=To%20use%20a%20button%20as%20a%20link%20in,browser%20to%20navigate%20to%20the%20specified%20page.%20App.js

<Link to="https://discord.gg/Zrk8kXfs">
  <Button text="Join Our Discord" />
</Link>

LOL, was literally typing the same thing as the above

about 4 years ago · Juan Pablo Isaza Report

0

You shouldn't use the a tag inside the button. It will confuse the screen reader for some browsers. Instead, you should use the tag as its functionality

I've updated your code:

import React from "react";
import styled from "styled-components";

const StyledLink = styled.a`
  display: inline-block;
  background-color: #efefef;
  color: ${(props) => props.theme.body};
  outline: none;
  border: none;

  text-decoration: none;

  font-size: ${(props) => props.theme.fontsm};
  padding: 0.9rem 2.3rem;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;

  &:hover {
    transform: scale(0.9);
  }

  &::after {
    content: " ";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    border: 2px solid ${(props) => props.theme.text};
    width: 100%;
    height: 100%;
    border-radius: 50px;
    transition: all 0.2s ease;
  }

  &:hover::after {
    transform: translate(-50%, -50%) scale(1);
    padding: 0.3rem;
  }
`;

const Button = ({ text, link }) => {
  return (
    <StyledLink href={link} aria-label={text} target="_blank" rel="noreferrer">
      {text}
    </StyledLink>
  );
};

export default Button;

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!