Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gatsby-plugin-catch-links] Links fail when domain name is included in link #3546

Closed
stefvhuynh opened this issue Jan 16, 2018 · 6 comments
Closed
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@stefvhuynh
Copy link

stefvhuynh commented Jan 16, 2018

When you have an anchor tag in markdown, links are not prefixed (#3316); therefore opening the link in a new tab fails. To get around this, you can pass in the absolute url instead of just a relative url.

However, when you just click on the link regularly, it will append the entire absolute url to the existing url. The reason is because of this line: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-catch-links/src/catch-links.js#L61. The entire href attribute gets passed in when the host of the href matches the host of the page you are on.

Would it be possible to change this line to

cb(anchor.pathname)

This would solve the issue but I'm not sure if it'll be problematic for others.

@stefvhuynh stefvhuynh changed the title Links fail when domain name is included in link [gatsby-plugin-catch-links] Links fail when domain name is included in link Jan 16, 2018
@KyleAMathews
Copy link
Contributor

Does the pathname exist on the anchor? If it does that sounds fine.

@stefvhuynh
Copy link
Author

yeah, usually for these links, you'd pass in <a href="/some/path">. so it's working now because anchor.getAttribute('href') returns that property verbatim. but it won't work if you do <a href="https://mydomain.com/some/path">. This will result in pushing mydomain.com/some/path to the end of the current url. However, if you use anchor.pathname, you will get /some/path in both examples, which will result in correct navigation behavior.

@KyleAMathews
Copy link
Contributor

We should detect if the link is pointed to a different domain and then let the browser handle the link click normally.

A PR for this would be great!

@alem0lars
Copy link

Any updates?

@kakadiadarpan kakadiadarpan added the type: bug An issue or pull request relating to a bug in Gatsby label Sep 27, 2018
@kakadiadarpan
Copy link
Contributor

@alem0lars There's a PR already open for this issue - #7779

Once it is merged the fix will be available for Gatsby v1, this issue has already been fixed for Gatsby v2. If you want to give that a try, we have nicely written migration guide.

@kakadiadarpan
Copy link
Contributor

Fixed in #7779

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

4 participants