简体   繁体   中英

external link getting appended with localhost url

I'm trying to redirect users to external links but the following code is always

<a href={`"https://"${posts.ctaURL1}`}

redirecting users to http://localhost:8080/%22https://%22www.fb.com

The external link won't be necessary https it can be http as well and url is dynamically filled. How to solve this issue?

It seems that posts.ctaURL1 also contains https , so that's why you get such a strange url. You could try

<a href={posts.ctaURL1}>click here</a>

If you want to replace https with http you can use string replace.

let url = posts.ctaURL1.replace("https", "http")
<a href={url}>click here</a>

This is how I solved the problem.

a href={`http://${posts.ctaURL1}`}

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