question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hosting environments that add a trailing back slash break page links

See original GitHub issue

🐛 Bug Report

Hosting setups that add a trailing back slash to urls break all inter-site links on the page.

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. Create two new sub folders in docs called a and b
  3. Add attached file a.md to a folder, and b.md to b folder.
  4. Replace sidebar.js with attached version.
  5. run npm run build to generate the flat site.
  6. Load the site in any browser by navigating directly to the url of page a: http://127.0.0.1:8080/docs/a/a
  7. Click the link Link to page "b"

Expected behavior

Page b should load.

Actual Behavior

Page Not Found page.

Your Environment

  • Docusaurus version used: 2.0.0-alpha.48
  • Environment name and version (e.g. Chrome 78.0.3904.108, Node.js 10.17.0): Safari 13.0.5 (15608.5.11), Chrome 80.0.3987.132, Firefox 73.0.1
  • Operating system and version (desktop or mobile): macOS 10.15.3 (19D76)

Reproducible Demo

(Paste the link to an example repo, including a siteConfig.js, and exact instructions to reproduce the issue.)

http://littlespex.com/docusaurus/docs/a/a

test-site.zip

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
dotansimhacommented, May 19, 2020

My current way to workaround that:

  1. Create a file called static/js/fix-location.js with:
if (window && window.location && window.location.pathname.endsWith('/') && window.location.pathname !== '/') {
  window.history.replaceState('', '', window.location.pathname.substr(0, window.location.pathname.length - 1))
}
  1. Load this file as static JS file in docusaurus.config.js:
  scripts: [
    {
      src: '/js/fix-location.js',
      async: false,
      defer: false,
    },
4reactions
veeramarnicommented, Apr 27, 2021

I’m having the same issue, it breaks URL navigation due to HTTP proxy services. I use `Nginx in the docker, when I directly open a link without trailing slash, it redirects to HTTP domain with the port used in Nginx. Since we don’t run on 443 port it breaks the public link.

For example, if I try to open https://domain.com/a it redirects to http://domain.com:8080/a/ and it fails to load the page. But if you open https://domain.com/a/ it works fine. Does anyone have the same issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

When should I use a trailing slash in my URL?
The trailing slash seems to mitigate any concerns, allowing the page to rank in search engines and get by virus checkers.
Read more >
Trailing Slashes on URLs: Contentious or Settled?
A post by Zach Leatherman (zachleat)
Read more >
Should You Have a Trailing Slash at the End of URLs?
A trailing slash is a forward slash (“/”) placed at the end of a URL such as domain.com/ or domain.com/page/. But should you...
Read more >
Trailing Slashes in URLs – What is the Preferred Style?
With the trailing slash, the server assumes that the request is a directory and not a file. The result will either be a...
Read more >
Deploying to Github Pages? Don't Forget to Fix Your Links
Root-relative links are links that start with a forward slash ( / ). When clicked, a root-relative link ignores the path location of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found