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

Add support for relative links with @reach/router #6945

Closed
KyleAMathews opened this issue Aug 1, 2018 · 20 comments
Closed

Add support for relative links with @reach/router #6945

KyleAMathews opened this issue Aug 1, 2018 · 20 comments

Comments

@KyleAMathews
Copy link
Contributor

Currently this doesn't work due to how we render routes. This seems like something that can be fixed.

@kakadiadarpan
Copy link
Contributor

@KyleAMathews is this issue fixed?

@Mike-Dax
Copy link
Contributor

@kakadiadarpan I just noticed this issue when upgrading from one of the beta releases to v2.0.6.

@KyleAMathews
Copy link
Contributor Author

No this is still a problem actually /cc @ryanflorence

@gatsbot
Copy link

gatsbot bot commented Jan 12, 2019

Old issues will be closed after 30 days of inactivity. This issue has been quiet for 20 days and is being marked as stale. Reply here or add the label "not stale" to keep this issue open!

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Jan 12, 2019
@gatsbot
Copy link

gatsbot bot commented Jan 24, 2019

This issue is being closed due to inactivity. Is this a mistake? Please re-open this issue or create a new issue.

@gatsbot gatsbot bot closed this as completed Jan 24, 2019
@Mike-Dax Mike-Dax reopened this Jan 24, 2019
@Mike-Dax
Copy link
Contributor

This is still an issue.

@gatsbot
Copy link

gatsbot bot commented Feb 4, 2019

Hey again!

It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.

Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.

Thanks again for being part of the Gatsby community!

@gatsbot gatsbot bot closed this as completed Feb 4, 2019
@sgnl
Copy link

sgnl commented Feb 7, 2019

Not exactly sure if this is on topic because the description is a little vague but...

✔️ I'm able to implement relative links if I use Link from '@reach/router'

🐛 I'm unable to implement relative links when using Link from 'gatsby'

Links to code references related to my comments...

withPrefix method in GatsbyLink component -

export function withPrefix(path) {
return normalizePath(`${__PATH_PREFIX__}/${path}`)
}

(updated: removed old references; added updated reference to withPrefix with commit hash blob instead of alias branched name)

@bryndyment
Copy link
Contributor

This is still an issue.

@bryndyment bryndyment reopened this Apr 16, 2019
@wardpeet wardpeet added not stale and removed stale? Issue that may be closed soon due to the original author not responding any more. labels Apr 16, 2019
@ryami333
Copy link

Is using @reach/router within a gatsby app "allowed"? Because this solves this problem for our use-case, but I'm not sure what the wider implications are.

@lucletruc
Copy link

Still an issue!

@agentofuser
Copy link
Contributor

Related: #14161

@github-actions
Copy link

github-actions bot commented Dec 9, 2019

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@github-actions github-actions bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Dec 9, 2019
@chadly chadly added not stale and removed stale? Issue that may be closed soon due to the original author not responding any more. labels Dec 9, 2019
@devuxer
Copy link

devuxer commented Feb 23, 2020

@KyleAMathews, If this isn't something that can be fixed soon, could there at least be a sentence in the docs saying that relative links are not supported? Having ported over some code from @reach/router, I was completely mystified why relative links were not working.

@patspam
Copy link

patspam commented Mar 23, 2020

Just wasted an hour on this - a note in the doc would be much appreciated by the next N people who run into this..

@sidharthachatterjee
Copy link
Contributor

@ascorbic added support for this in #24054 🎉

@guillaumebriday
Copy link
Contributor

@KyleAMathews @ascorbic Hey!

I think this PR has broken the Link behaviour. I got something like that in a component:

<Link to={post.fields.slug}>
  {post.frontmatter.title}
</Link>

This link is under the page /articles and the post.fields.slug is just a string.

Before it was rendered as (excepted result):

<a href="/my-slug">

and now (wrong):

<a href="/articles/my-slug">

I think many sites will be affected by this modification.

How could we fix it? Thank you in advance

@ascorbic
Copy link
Contributor

@guillaumebriday I'm guessing the slug doesn't start with a slash? That means it's a relative link, so this is expected behaviour. Previously it would have given you a warning as it was unsupported, even if it happened to work. You can get the correct behaviour in your case by adding a slash to the start of the link.

@guillaumebriday
Copy link
Contributor

@ascorbic It doesn't. I use allMarkdownRemark with the createFilePath method from gatsby-source-filesysteme to generate a slug field.

By default it does not prefix with a slash.

I fixed it in https://github.com/guillaumebriday/guillaumebriday.fr/commit/36d1848f3fe931ce74dacdd83c451a9698542cce

But I think there are plenty of applications with this behavior.

Anyway, thanks for the help 🙏

@LekoArts LekoArts removed the not stale label Jul 3, 2020
@drake-smith
Copy link

drake-smith commented Aug 30, 2020

I have 3-deep, 4-deep nested routes and need to relative on relative links to work.

Per https://www.gatsbyjs.com/docs/gatsby-link/ I should be able to pass a slug ../page to <Link> and have it render the proper relative link. Instead <Link> is stripping the .. and rendering /page and so it is not properly allowing for a relative path.

Gatsby version: "gatsby": "^2.23.12",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests