Skip to content

Anchor links across pages are failing #5020

Closed

Description

@teikjun

🐛 Bug Report

Prerequisites

Description

Anchor links that target headers in other pages are failing. Instead of sending users to the target header, users are sent to the top of the page.

Have you read the Contributing Guidelines on issues?

Yes

Steps to reproduce

  1. Go to this link: https://docusaurus.io/docs/using-themes#writing-customized-docusaurus-themes
  2. Click on getThemePath()

image

Expected behavior

Expected to go to the target header

Actual behavior

Get sent to the top of the page
image

Your environment

  • Docusaurus version used: 2.0.0-beta.1
  • Environment name and version (e.g. Chrome 78.0.3904.108, Node.js 10.17.0): Firefox 89, Chrome 91

Reproducible Demo

Demo 1

  1. Go to https://deploy-preview-4797--docusaurus-2.netlify.app/docs/using-themes#writing-customized-docusaurus-themes
  2. Click on the getThemePath() link

Demo 2

  1. Go to https://deploy-preview-4811--docusaurus-2.netlify.app/docs/deployment#self-hosting
  2. Click on the docusaurus serve link

Root Causes

There are 2 root causes here - they correspond to the 2 demos above.

Root cause for Demo 1

PR #4797 is the earliest PR that has the bug, so I believe it is the root cause of the regression. Adding back the !hash condition (as shown below) resolves this bug, but I'm not sure if this is the right approach.

image

@lex111 @slorber, could I get your advice on this? 🙏

Root cause for Demo 2

Demo 2 is the state before PR #4797 was merged. Certain anchor links still fail. This is due to incorrect anchor link specified on the user side. I will open a PR to resolve this.

Activity

  1. added
    bug
    status: needs triage
    on Jun 20, 2021
  2. lex111 commented on Jun 20, 2021

    @lex111
    Contributor

    @teikjun thanks for the report, yes, you're right, we should ignore hash changes in that hook, my bad, will be fixed in #5023.

  3. removed
    status: needs triage
    on Feb 22, 2022
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions