Answer the question
In order to leave comments, you need to log in
How to match https://site.com and site.com links in react app?
2 links come from the database
url1 = ' https://facebook.com '
url2 = 'github.com'
<a href={props.url1}>Facebook</a> //Переходит на сайт как абсолютная ссылка
<a href={props.url2}>Github</a> //Переходит localhost/github.com как относительная ссылка
Answer the question
In order to leave comments, you need to log in
before displaying the link, you can check for the presence of schema and if not, do your magic.
console.log(/https?:\/\/.*?/.exec('https://github.com'));
// ["https://", index: 0, input: "https://github.com", groups: undefined]
console.log(/https?:\/\/.*?/.exec('github.com'));
// null
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question