website icon indicating copy to clipboard operation
website copied to clipboard

bug: Broken links depending on the window history

Open GeniusTimo opened this issue 11 months ago • 3 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Description of the bug

I have come across some strange behaviour as I make my way through the documentation. When I open the page using a direct link, some relative links seem to be broken, although they work when I visit a page within the folder first. I wanted to report this behaviour as I'm not familiar enough with this type of problem. Other sites with ./ links also have this problem.

Steps To Reproduce

  1. Open https://sapphirejs.dev/docs/Guide/commands/application-commands/what-are-application-commands
  2. Click on the link "Application Command Registry" in the last sentence of this page
  3. You get redirected to https://sapphirejs.dev/docs/Guide/commands/application-commands/what-are-application-commands/application-command-registry/what-is-it

Expected behavior

You get redirected to https://sapphirejs.dev/docs/Guide/commands/application-commands/application-command-registry/what-is-it

Screenshots

No response

Additional context

Steps to reproduce the same link working properly:

  1. Open https://sapphirejs.dev/docs/Guide/commands/application-commands/application-command-registry/acquiring-an-application-command-registry
  2. Click on the link "What are application commands?" in the sidebar
  3. You get redirected to https://sapphirejs.dev/docs/Guide/commands/application-commands/what-are-application-commands
  4. Click on the link "Application Command Registry" in the last sentence of this page
  5. You get redirected to https://sapphirejs.dev/docs/Guide/commands/application-commands/application-command-registry/what-is-it (expected behavior)

System Info

N.A.

GeniusTimo avatar Jan 20 '25 18:01 GeniusTimo

I think I have found the bug that is causing this problem as I was trying the updated version. Visiting the site directly adds an / at the end of the path if there isn't one already. If I interact with the sidebar the site navigates me to to the path without the / at the end. Therefore relative links get confused.

As outlined in https://github.com/sapphiredev/website/pull/294#pullrequestreview-2574109596 the pull request did fix the issue I was describing but broke it the other way around as the real issue was not the relative link being incorrect but rather the / that gets added to the path if you visit the site directly / via an external site.

To fix this issue, #294 needs to be reverted and the cause for the / needs to be identified and removed (or added to all the sidebar links and adjusted accordingly)

GeniusTimo avatar Feb 17 '25 18:02 GeniusTimo

I tried looking into this more and for the life of me I cannot find a proper solution. Especially since the sidebar and a lot of the site are generated from markdown files.

favna avatar Jun 10 '25 22:06 favna

Probably it's worth taking a look at the Docusaurus config field trailingSlash and the resources linked over there. Otherwise I'd suggest using absolute instead of relative links to mitigate this issue

GeniusTimo avatar Jun 13 '25 11:06 GeniusTimo