facebook / facebook/docusaurus

Unable to avoid prepending of the baseUrl in NavBar items

Open
#8,006 5 comments 2 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
66.2k
Forks
10k
Avg merge
1d 3h
Merged PRs (30d)
52

Description

### Have you read the Contributing Guidelines on issues?

- [X] I have read the [Contributing Guidelines on issues](https://github.com/facebook/docusaurus/blob/main/CONTRIBUTING.md#reporting-new-issues).

### Prerequisites

- [X] I'm using the latest version of Docusaurus.
- [X] I have tried the `npm run clear` or `yarn clear` command.
- [X] I have tried `rm -rf node_modules yarn.lock package-lock.json` and re-installing packages.
- [X] I have tried creating a repro with https://new.docusaurus.io.
- [X] 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:
```js
{
href: '/toto', // or 'pathname:///toto'
prependBaseUrlToHref: false,
label: 'Toto',
position: 'left'
}
```
4. In the broswer go `/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

- Public source code: https://stackblitz.com/edit/github-tvsjbv?file=docusaurus.config.js
- Public site URL: https://stackblitz.com/edit/github-tvsjbv?file=docusaurus.config.js
- Docusaurus version used: 2.0.1
- Environment name and version (e.g. Chrome 89, Node.js 16.4): Chrome 104
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): Mac OSX 12.1

### Self-service

- [ ] I'd be willing to fix this bug myself.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.