Skip to content

Markdown Header Anchor Links do not work on page load #2399

Closed

Description

@Noah-Silvera

🐛 Bug Report

Each markdown header has a targeted anchor link which corresponds to a URL.
i.e. http:///docs/mobile/doc1#header1

If you click on the headers in the right sidebar when the documentation is loaded, the page scrolls to the header that is the anchor link target as expected.

But, if you copy a link to one of the headers with a anchor # in it, and paste it into a new tab, the page does not scroll to the appropriate header on page load.

Have you read the Contributing Guidelines on issues?

yes

To Reproduce

  1. Create a new site using npx @docusaurus/init@next init test-site classic
  2. yarn start
  3. Open http://localhost:3000/docs/doc1#admonitions

Expected behavior

The page doc1 is opened and scrolled to the admonitions header

Actual Behavior

The page doc1 is opened but not scrolled to the admonitions header

Your Environment

  • Docusaurus version used:
    "@docusaurus/core": "^2.0.0-alpha.48",
    "@docusaurus/preset-classic": "^2.0.0-alpha.48",
  • Chrome Version 80.0.3987.132
  • Windows 10 Desktop

Reproducible Demo

This repo is an unmodified npx @docusaurus/init@next init test-site classic but including for completeness
https://github.com/Noah-Silvera/docusaurus-anchor-links-bug

Activity

  1. added
    bug
    status: needs triage
    on Mar 10, 2020
  2. lex111 commented on Mar 11, 2020

    @lex111
    Contributor

    Is there a similar bug on the builded website? This should be relevant only in development mode.

  3. Noah-Silvera commented on Mar 11, 2020

    @Noah-Silvera
    ContributorAuthor

    No there is no similar bug in prod. It only affects development mode.

  4. lex111 commented on Mar 11, 2020

    @lex111
    Contributor

    In dev mode, we do not use SSR, so this issue occurs. I do not think this is a serious bug, since there is no such thing in the production build. This may not be very comfortable, although it is unlikely that you will often use anchors links in dev mode 🤷‍♂️.

  5. Noah-Silvera commented on Mar 11, 2020

    @Noah-Silvera
    ContributorAuthor

    Should we just close this issue then? Seems very minor if it only affects dev mode.
    Might be worth documenting under https://v2.docusaurus.io/docs/markdown-features#markdown-headers?

  6. Mauriceac commented on Apr 29, 2021

    @Mauriceac

    I have this bug even after building.

    Any workaround (other than refreshing, which effectively works)?

  7. jsphstls commented on Aug 24, 2021

    @jsphstls

    I see the same bug for builds with "@docusaurus/core": "2.0.0-beta.4"

    Edit:
    Anchor links are working in both dev and prod mode once I moved all official @docusaurus/* packages to the exact same version as per the output warning. The anchor link must also be lowercase, despite VsCode accepting any case when moving between markdown files. CC @Mauriceac

  8. jsphstls commented on Aug 24, 2021

    @jsphstls

    I found a cross-page anchor link that is working on the current Docusaurus site. See the “multi-instance plugins” link under https://docusaurus.io/docs/blog#multiple-blogs.

  9. k8w commented on Nov 28, 2021

    @k8w

    Still have this problem, latest version

  10. Mauriceac commented on Nov 29, 2021

    @Mauriceac

    Still have this problem, latest version

    @k8w, me too. You might want to follow issue 3081. It explains the problem, although no solution has been given yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugstatus: needs triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions