Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k 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 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...