[英]link tag redirect issue in react.js
I have links saved in the firebase DB, when I click "save" the link it will updated but when I click to the link icon it redirect me to home page.我在 firebase DB 中保存了链接,当我单击“保存”时,链接会更新,但是当我单击链接图标时,它会将我重定向到主页。 Example: The link in the DB is "www.instagram.com", when I click the icon it will redirect me to the home with this url "localhost:3000/www.instagram.com", but when I do the console log it logs only "www.instagram.com", can somebody help me please?
示例:数据库中的链接是“www.instagram.com”,当我单击该图标时,它将使用此 url“localhost:3000/www.instagram.com”将我重定向到家,但是当我执行控制台日志时它只记录“www.instagram.com”,有人可以帮帮我吗?
formInputs it's a simple object formInputs 它是一个简单的 object
<a
target="_blank"
href={formInputs.ig}
onClick={() => {
console.log(formInputs.ig);
}}
>
<FontAwesomeIcon
className="icons"
icon={faInstagram}
color="purple"
size="2x"
/>
</a>
I tryed to use the Link component from react-router-dom but it do the same thing我尝试使用 react-router-dom 中的 Link 组件,但它做同样的事情
In short: please try to use a full absolute URL together with the protocol.简而言之:请尽量使用完全绝对的 URL 和协议。 Instead of a short one.
而不是短的。 In this case, can change the value to
https://www.instagram.com
.在这种情况下,可以将值更改为
https://www.instagram.com
。
Document source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a文档来源: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a
Possible values of href
: href
的可能值:
The key difference is the //
at the beginning.关键区别在于开头的
//
。 Without it, your browser is considering your given "www.instagram.com"
as a relative URL and is trying to calculate the path based on your current location.没有它,您的浏览器会将您给定的
"www.instagram.com"
视为相对 URL 并尝试根据您当前的位置计算路径。
And if you're only using //www.instagram.com
, the browser will use the same protocol as the current page, eg http://localhost
-> http://www.instagram.com
And if you're only using
//www.instagram.com
, the browser will use the same protocol as the current page, eg http://localhost
-> http://www.instagram.com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.