Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to navigate to an external URL?

I'm creating a simple App in React , using React Router v4, with this structure

-Wrapper
 -Home /
 -Homepage /h
    --GalleryContainer  /h/gallery
       ---Gallery  /h/gallery
       ---Item    /h/gallery/:itemId
    --About /h/about
    --Links /h/links

in Links, there is a list of elements that redirects to external links. Problem is, when you click on url www.example.com, it goes to http://localhost:7770/h/www.example.com and render 404 link not found

Here is the code

<div className="links">
        <ul>
          {link.links.map((url,i)=>
            <li key={i}><a href={url}>{url}</a></li>)}
        </ul>
      </div>

with url being www.example.com or any weblink.

How do you make url goes to www.example.com and not http://localhost:7770/h/www.example.com?

like image 989
Ndx Avatar asked Oct 09 '17 21:10

Ndx


People also ask

How to redirect to external URL React?

You can use the Link component or an HTML anchor tag if you want to redirect to an external link with React Router. Using the < Link > component, you can do it thanks to the pathname and target parameters. It will redirect the user to the specified URL.

What is external redirect?

URL redirection is forwarding a user from one page to another page. There are basically two types of redirection:- Internal Redirection: Forwarding to internal pages. External Redirection: Forwarding to external pages (Other domains).

How do I redirect an external URL from Angular2 route without using component?

You can achieve what you want with a trick using the resolve option of a route. Resolve is some data value that Angular2 will obtain for the route to be initialized. More details you can find here in the official documentation. This will redirect to the external URL.


1 Answers

You should add http:// to the beginning of your url. So your code should be

<li key={i}><a href={"http://"+url}>{url}</a></li>
like image 77
palsrealm Avatar answered Sep 24 '22 18:09

palsrealm