Skip to content
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

Unable to avoid prepending of the baseUrl in NavBar items #8006

Open
6 of 7 tasks
jbltx opened this issue Aug 25, 2022 · 5 comments
Open
6 of 7 tasks

Unable to avoid prepending of the baseUrl in NavBar items #8006

jbltx opened this issue Aug 25, 2022 · 5 comments
Labels
bug An error in the Docusaurus core causing instability or issues with its execution

Comments

@jbltx
Copy link

jbltx commented Aug 25, 2022

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

Using the prependBaseUrlToHref property on NavBar items or pathname:/// inside href property directly doesn't prevent the prepending of the project's baseUrl value in the final link.

Reproducible demo

https://stackblitz.com/edit/github-tvsjbv?file=docusaurus.config.js

Steps to reproduce

  1. Set a baseUrl in the docusaurus config file other than / (example : /base/)
  2. Set the docusaurus project as Docs-only (docs.routeBasePath : /, intro.md slug: /, remove src/pages folder)
  3. Add NavBar links that should point to other place in the same domain. Example:
    {
      href: '/toto', // or 'pathname:///toto'
      prependBaseUrlToHref: false,
      label: 'Toto',
      position: 'left'
    }
  4. In the broswer go <yourdomain>/base to get the docs intro page.
  5. Check the final href value of links inside the NavBar.

Expected behavior

The navbar item links shouldn't have the baseUrl prepended on the href

https://your-docusaurus-test-site.com/toto

Actual behavior

The navbar item links do have the baseUrl prepended on the href

https://your-docusaurus-test-site.com/base/toto

Your environment

Self-service

  • I'd be willing to fix this bug myself.
@jbltx jbltx 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 Aug 25, 2022
@slorber
Copy link
Collaborator

slorber commented Aug 25, 2022

The default sidebar item link is legacy and quite messy. I'd like to refactor it and make things clearer but it's not easy without changing the behavior and doing breaking changes.

In the meantime, I think you should be able to achieve what you want with autoAddBaseUrl: false.

Related to #7949

I guess we can keep this issue open, and probably remove prependBaseUrlToHref in favor of autoAddBaseUrl

@slorber slorber added bug An error in the Docusaurus core causing instability or issues with its execution and removed 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 Aug 25, 2022
@jbltx
Copy link
Author

jbltx commented Aug 26, 2022

autoAddBaseUrl seems to do the trick yes, thank you!

I don't think the property autoAddBaseUrl is documented :
https://docusaurus.io/docs/api/themes/configuration#navbar-link

@slorber
Copy link
Collaborator

slorber commented Aug 26, 2022

No it's not documented. All things regarding linking are a bit messy, a mix of new features and legacy things I'd like to get rid of. We'll document everything once the cleanup/breaking changes are done

@CMCDragonkai
Copy link

Finally found this. I was wondering why it didn't work. BTW, what's the point of using pathname://? I can see that href: '/' with autoAddBaseUrl: false working now.

@CMCDragonkai
Copy link

The autoAddBaseUrl doesn't appear to work for navbar.logo atm.

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
Projects
None yet
Development

No branches or pull requests

3 participants