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

Anchor link / fragment Link back button issue #26959

Closed
don-esteban opened this issue Sep 19, 2020 · 4 comments
Closed

Anchor link / fragment Link back button issue #26959

don-esteban opened this issue Sep 19, 2020 · 4 comments
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@don-esteban
Copy link

Back button with anchor/fagmenmt links don't go back to last position. Tested with Firefox 80.0, Chrome 85.0.4183.83 and Safari 13.1.2 on macOS 10.15.6.

Reproduction steps (and many pages in the online docs):

gatsby new my-blog-starter https://github.com/gatsbyjs/gatsby-starter-blog
npm update

Insert this two lines somewhere in content/blog/new-beginnings/index.md

[Go to (markdown link)](#gohere)
<a href="#gohere">Go to (a href link)</a>

Insert the anchor somewhere below

<h3 id="gohere">Here You are. Now press the backbutton.</h3>

Back Button will not work:

  1. Visit start page http://localhost:8000/
  2. Click "New Beginnings"
  3. Click one of the anchor links
  4. Click back button

Won't return to top of page or previous position.

Back Button still won't work:

  1. Click browser refresh button
  2. Same as above

Back Button will work:

  1. Click in URL address input and hit enter key or visit http://localhost:8000/new-beginnings/ directly
  2. Now back button works as expected

Originally posted by @don-esteban in #8019 (comment)

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Sep 19, 2020
@LekoArts LekoArts added topic: reach/router and Links type: bug An issue or pull request relating to a bug in Gatsby and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Sep 21, 2020
@don-esteban
Copy link
Author

This seems to be a nontrivial issue. Does anyone know a work-around? Our visitors use this functionality intensively jumping between table of contents and content. We can't go productive with our Gatsby-site.

@don-esteban
Copy link
Author

Let me come back to this serious but still unresolved issue. I don't know, how other productive sites, if existent, handle this bug. Perhaps they live with the broken back button behavior mostly in conjunction with fragment links? One example for broken fragment links are the Gatsby API Docs itself, like https://www.gatsbyjs.com/docs/gatsby-link/ Using the right sidebar does not work at all.

For our site I found a workaround. Let me know if I can help with something, perhaps with fixing some doc issues? Unfortunately I'm not experienced enough to go inside the reach/router and Link implementation. So I have to wait for someone else fixes this issue. Sorry for that.

It seems like the issue is only present when mixing <Link /> components and <a /> tags. To work around this problem, we implemented an own Table of Content component, which uses <Link /> and not <a /> as the https://www.gatsbyjs.com/plugins/gatsby-remark-table-of-contents/ does.

We do not use Markdown links []() neither. We use the <Link /> component in all MDX files for fragment links. For internal links to other pages we use Markdown syntax in conjunction with the gatsby-plugin-catch-links plugin.

Honestly. This workaround in content files (MDX) is critical. We have to convert about 5.000 pages and content authors have to "pollute" the content with Gatsby-Link-Components. I let You know how things are going.

@dbismut
Copy link
Contributor

dbismut commented Oct 18, 2020

This issue is related and has been marked as closed #27431

@don-esteban
Copy link
Author

I tried to reproduce the error again with the latest Gatsby version 2.24.80. All issues are gone.

Important note! The work around above is not needed any more and would not work anymore! Stay with this simple rule:

  1. For links to other pages use the Link component
    <Link to="other-page">Other page link</Link>
  2. For fragement links (anchor links, links to the same page) use the HTML a-tag
    <a href="#fragment-link">Same page link</a>

Not sure when this issue was fixed nor who fixed it. Thanks a lot.

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

3 participants