gpt4 book ai didi

reactjs - 为什么我的 React 应用程序将外部 URL 附加到 http ://localhost:/ and not to ONLY the URL itself?

转载 作者:行者123 更新时间:2023-12-03 20:28:22 26 4
gpt4 key购买 nike

在我的 ReactJS 应用程序 (create-react-app) 中,我有一个 anchor 标记,带有指向外部 URL www.google.com 的旧 href 属性,当我单击该 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://,浏览器会认为它是本地链接。

关于reactjs - 为什么我的 React 应用程序将外部 URL 附加到 http ://localhost:/<port> and not to ONLY the URL itself?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56029447/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com