React router V4 link to external address

Viewed 7933

I've tried a few different recommendations, however, none seem to work. I'm using react router V4 and I would like to create a link that navigates to an external website. Currently, everything I do just appends to my URL.

What I want to happen www.mysite.com => click internal link and go to => www.newsite.com

What is happening www.mysite.com => click internal link and go to new page but it appends => www.mysite.com/www.newsite.com

<Link to="http://www.newsite.com">Go to new site</Link>

2 Answers

The solution to this was what @Giri suggested, a simple HTML link.

<a href="http://www.newsite.com">New site</a>

You can also create your own component as suggested here:

import React from 'react'
import {Link} from 'react-router-dom'

const Anchor = (props) => {
  return props.href ?
    <a {...props}/>
    :
    <Link {...props}/>
};

export default Anchor
Related