Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't open new tab in react, adds localhost:3000 on link?

Tags:

reactjs

i have used react router doms' Link:

<Link target="_blank" to={"www.mylink.com"} >mylink </Link>

but this would open new tab to http://localhost:3000/www.mylink.com also, using a href:

<a href={'www.mylink.com'} target="_blank" > mylink </a>

does the same. opens new tab to http://localhost:3000/www.mylink.com how do i open in new tab only the link?

like image 796
gpbaculio Avatar asked Nov 23 '17 04:11

gpbaculio


2 Answers

try this

<Link target="_blank" to={"//www.mylink.com"} >mylink </Link>

or this

<a href={'//www.mylink.com'} target="_blank" > mylink </a>

for more reference:
Absolute vs relative URLs
https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Generic_syntax

like image 199
am05mhz Avatar answered Nov 15 '22 12:11

am05mhz


I tried to use Link but I had the same problem. Now I'm using this onClick={() => { window.open('LINK','_blank')}}

like image 1
Pelin Kayhan Avatar answered Nov 15 '22 10:11

Pelin Kayhan