Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to get a button to link to a website using react.js but I can't seem to figure out how to get it working. From the code below everything works perfectly except for the button (props.website). Nothing happens when I click the button. What am I doing wrong?

   function Card(props){
    return(
        <MDBCol>
<MDBCard style={{ width: "22rem" }}>
  <MDBCardImage className="img-fluid" src={props.image} waves />
  <MDBCardBody>
    <MDBCardTitle>{props.name}</MDBCardTitle>
    <MDBCardText>
    {props.meaning}
    </MDBCardText>
    <MDBBtn href={props.website} >View Project</MDBBtn>
  </MDBCardBody>
</MDBCard>
</MDBCol> 
    );
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
490 views
Welcome To Ask or Share your Answers For Others

1 Answer

From a comment on the question above:

it directs to localhost:3000/www.google.com

Then the link is actually working. But the URL is wrong. You appear to be using this URL:

'www.google.com'

But a browser has no way of knowing that this is another website. Structurally it's no different than, say, this:

'www.index.html'

Which is a perfectly valid name for a resource on your website.

To tell the browser that this should go to another website, include the protocol:

'http://www.google.com'

Or at least the // at the start to default to whatever the current page's protocol is:

'//www.google.com'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...