Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

reactjs - Why can't I get redirect to a weblink(in this case to 'twitter.com/explore;) I mentioned in this react code?

The code:

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;

It does show this in the URL of my project-> http://localhost:3000/https://twitter.com/explore But clicking on that element I can't go to the desired web link that I provided


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can not use NavLink / Link to an external url, it is just used for application path.

You need to use a normal a tag:

<a href="https://twitter.com/explore">{props.username}</a>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...