reactjs - 为什么我不能重定向到我在这个反应代码中提到的网络链接(在这种情况下是 ''twitter.com/explore'')?
问题描述
编码:
import React from "react";
import "./App.css";
import "./Square.css";
import { thestack } from "./thestack";
import { Link, Router, NavLink } from "react-router-dom";
//import { Link } from 'react-router';
function Square(props) {
return (
<div className="Square">
<p>
<NavLink to={"https://twitter.com/explore"}>
{props.username} <br />
</NavLink>
{props.sitcoms_one} <br />
{props.sitcoms_two} <br />
{props.sitcoms_three} <br />
{props.sitcoms_four} <br />
{props.sitcoms_five}
</p>
</div>
);
}
export default Square;
它确实在我的项目的 URL 中显示了这一点-> http://localhost:3000/https://twitter.com/explore 但是单击该元素我无法转到我提供的所需网络链接
解决方案
您不能使用 NavLink / 链接到外部 url,它仅用于应用程序路径。
您需要使用普通a
标签:
<a href="https://twitter.com/explore">{props.username}</a>
推荐阅读
- date - 批处理:如何导出昨天的日期保存格式[mm/dd/yyyy]?
- javascript - 为什么要将现有的 jQuery 类“removeClass”传递给 IIFE?
- c++ - QImage::pixel 和 QImage::setPixel 坐标超出范围错误
- recursion - x86_64 程序集中的递归阶乘问题
- r - R中的formattable可以按变量对表进行分组吗?
- mysql - 为什么我在 mysql 的这个查询中出现语法错误
- matlab - 如何从(30x3)矩阵生成 10 个(3x3)矩阵并将其用于旋转矩阵
- ionic-framework - Ionic 4 键盘覆盖全部内容
- qt - 如何正确更改 QSlider 的元素
- python - 如何在sklearn中获得回归结果报告