gatsby-link for external links

Created on 24 Aug 2018  路  4Comments  路  Source: gatsbyjs/gatsby

Summary

Currently gatsby-link doesn't work properly with external links. Instead of showing the url, it append the url with the current url, it shows: http://localhost:8000/https:/mittalyashu.now.sh

Basic example

2018-08-24_19-53-04

It should have redirected to https://mittalyashu.now.sh

How it can be achieved?

By passing a parameter external.

<Link external to="https://mittalyashu.now.sh">External page</Link>

Most helpful comment

Based on the Gatsby docs linked, any external link appears to be just a simple <a> tag with an href as usual. However in my Gatsby application, when I follow this, I can not get the external links to work. My external href's are added to localhost:8000 and I get a 404 page not found. Am I missing something here?

<a href="www.github.com/maisonm" target="_blank" rel="noopener norefferer"> <img src={Github} alt="github logo" /> </a>

Solved. Just a lazy oversight on my end, but I am leaving this here for anyone else who comes across this: you must use https:// or http:// in the href tag for an external link to work.

All 4 comments

Gatsby鈥榮 Link component shouldn鈥檛 be used for external links:
https://next.gatsbyjs.org/docs/gatsby-link/#use-link-only-for-internal-links

Based on the Gatsby docs linked, any external link appears to be just a simple <a> tag with an href as usual. However in my Gatsby application, when I follow this, I can not get the external links to work. My external href's are added to localhost:8000 and I get a 404 page not found. Am I missing something here?

<a href="www.github.com/maisonm" target="_blank" rel="noopener norefferer"> <img src={Github} alt="github logo" /> </a>

Solved. Just a lazy oversight on my end, but I am leaving this here for anyone else who comes across this: you must use https:// or http:// in the href tag for an external link to work.

you must use https:// or http:// in the href tag for an external link to work.

This should really be in the docs.

Edit: I created a PR to add it to the docs.

target="_blank" rel="noopener norefferer"

@maisonm Thanks for this. Just a quick note that it should be noreferrer (small typo).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brandonmp picture brandonmp  路  3Comments

rossPatton picture rossPatton  路  3Comments

signalwerk picture signalwerk  路  3Comments

kalinchernev picture kalinchernev  路  3Comments

ghost picture ghost  路  3Comments