Skip to content

Markdown links point to root-level file when Markdown file with same filename exists #11099

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

Open
6 of 7 tasks
josh-wong opened this issue Apr 14, 2025 · 1 comment
Open
6 of 7 tasks
Labels
bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers

Comments

@josh-wong
Copy link
Contributor

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

When linking to a file within the documentation, the link sometimes resolves to an unintended file in the root docs directory rather than the expected file in the current or relative directory.

For example, suppose a page contains a link like [See this](index.mdx), and the current directory also contains a file named index.mdx. If a root-level docs/index.mdx also exists, the link will incorrectly point to the root file instead of the intended one in the current directory.

This behavior is not limited to index.mdx; it occurs with other filenames as well. It seems that the link resolution logic prioritizes the root docs directory over the relative path, which leads to incorrect navigation and potential confusion for users.

Workaround

If you start a link with ./ ([See this](./index.mdx)), then the issue doesn't occur. However, I don't think this is a solution because, as far as I know, using ./ isn't necessary when pointing to pages in the current directory.

Reproducible demo

https://clinquant-beijinho-49680d.netlify.app/docs/latest/scalardb-cluster/getting-started-with-scalardb-cluster

Steps to reproduce

  1. In the docs directory, create a file named index.mdx and add some basic text for testing to the file.
  2. In the docs directory, create a subdirectory named test.
  3. In the test subdirectory, create a file named index.mdx and add some text that is different from the text in the docs/index.mdx file that you created in step 1.
  4. In the test subdirectory, create a file named docusaurus.mdx and add the link [index](index.mdx) to the file.
  5. Build the site by running npm run build.
  6. Serve the site by running npm run serve.
  7. Go to the test/docusaurus page in your browser.
  8. Click the index link on that page. You will be taken to docs/index.mdx, which shows the basic text that you added in step 1.

Expected behavior

I was expecting to be routed to the page with the same filename in the subdirectory that I was in.

Actual behavior

I was routed to the root-level (docs) page with the same filename as that in the subdirectory that I was in.

Your environment

Self-service

  • I'd be willing to fix this bug myself.
@josh-wong josh-wong added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Apr 14, 2025
@josh-wong josh-wong changed the title Markdown links point to root-level file when Markdown with same filename exists Markdown links point to root-level file when Markdown file with same filename exists Apr 15, 2025
@sa-abdullah
Copy link

Kindly assign this to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers
Projects
None yet
Development

No branches or pull requests

2 participants