reactjs - 为什么我的 React 应用程序将外部 URL 附加到 http://localhost:/而不仅仅是 URL 本身?
问题描述
在我的 ReactJS 应用程序(create-react-app)中,我有一个锚标记,其中包含一个很好的旧 href 属性,指向外部 URL,www.google.com,当我单击该 DOM 元素时,应用程序会将目标 URL 附加到http://localhost:3000和URI 变为http://localhost:3000/www.google.com
我错过了什么?
我尝试过设置rel={'external'}
并尝试通过onClick={()=>{window.location.assign("www.google.com")}
import React from "react";
import {NavLink, Redirect} from "react-router-dom";
import TextLink from "../textLink/TextLink";
import "./footer.css";
/**
*
* @param {{theme: string}} props
*/
const Footer = props => {
const { theme } = props;
return (
<div className={`footer footer-${theme}`}>
<div className="wrapper">
<div id="social-media-icons">
<NavLink to={"/contact-us"}>
<i className="fab fa-facebook" />
</NavLink>
<a rel={'external'} className="fab fa-instagram" href={"www.google.com"} />
</div>
</div>
</div>
);
};
export default Footer;
我希望浏览器仅将我重定向到 www.google.com,并且基本上应该退出该应用程序。更好的是,在浏览器中使用所需的 URL 打开一个新窗口或选项卡。
解决方案
尝试这个
<a rel={'external'} className="fab fa-instagram"
target="_blank" href={"https://www.google.com"} />
这将打开新标签
target="_blank"
这将打开 google.com
href={"https://www.google.com"}
如果您不在 href 开头添加 https://,浏览器会将其视为本地链接。
推荐阅读
- c - Winsock2 线程参数抛出异常访问冲突
- cordova - 'mat-card' 不是已知元素,但我在其他页面上使用过它
- pfsense - 如何从命令行启动 pfSense 菜单?
- azure - Azure API 管理 - 如何使用 Azure CLI 设置 VNET/子网?
- python - 如何获取给定语音通道的 ID?- 不和谐.py
- python - 如何使用 python 从 csv 文件中绘制条形图?
- python - 如何在 tkinter python3 中为按钮添加边框颜色
- reactjs - state in useEffect 第二个参数 无限循环
- html - CSS - 如何更改滚动条高度
- python - 编辑 PATH 变量以正确使用 Pip 安装