-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I'm using the latest version of Docusaurus.
- I have tried the
npm run clearoryarn clearcommand. - I have tried
rm -rf node_modules yarn.lock package-lock.jsonand 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
I followed the documentation on the docusaurus website to add an i18n locale dropdown. By default my website is in French and I'm trying to implement an English translation. When I serve locally the built version of my project I have some problems with switching locale on either the homepage or the blog section depending on my docusaurus.config.js configuration. (see in steps to reproduce)
Reproducible demo
No response
Steps to reproduce
Here is a piece of my configuration in my file docusaurus.config.js :
// Production url
url: 'https://localhost:3000', // need to be changed
// /<baseUrl>/ pathname under which the documentation is served
baseUrl: '/user-doc/',
trailingSlash: false,
onBrokenLinks: 'throw',
onBrokenMarkdownLinks: 'warn',
// Even if you don't use internalization, you can use this field to set useful
// metadata like html lang.
i18n: {
defaultLocale: 'fr',
locales: ['fr', 'en'],
localeConfigs: {
fr: {
label: 'Français',
},
en: {
label: 'English',
},
},
},And a quick overview of my project (folders /docs/, /blog/ and /i18n/)
user-doc
│
├── blog
│ └── release-notes
│ ├── 1.1
│ ├── ...
│ └── 1.2
│ └── index.md
├── docs
│ ├── admin
│ └── user
├── i18n
│ ├── docusaurus-plugin-content-blog
│ | ├── release-notes
│ | │ ├── 1.1
│ | │ ├── ...
│ | │ └── 1.2
│ | │ └── index.md
│ | └──options.json
│ ├── docusaurus-plugin-content-docs
│ | ├── current
│ | │ ├── admin
│ | │ └── user
│ | └──current.json
│ ├── docusaurus-plugin-content-pages
│ └── docusaurus-theme-classic
│ ├── footer.json
│ └──navbar.jsonWhen I serve locally the built version of my project I have the following problems :
if I set trailingSlash: false :
On the homepage, anytime the english button on the dropdown is clicked it tries to go to /user-doc/en/ but I have a status 302 and I am directly redirected to /user-doc/
But if I go to /user-doc/en, I works but after the dropdown is broken... In debug thhe url on French looks like this /user-doc//user-doc/en and if I click on it I have a status 301 and I am getting redirected to /user-doc/en
On every other pages the dropdown is working.
if I set trailingSlash: undefined or trailingSlash: true :
When I am on the blog section (ex : /user-doc/blog/release-notes/1.1), anytime the english button on the dropdown is clicked it tries to go to the /user-doc/en/blog/release-notes/1.1 page and it shows the custom 404 and when you click it again it routes to /user-doc/en/en//blog/release-notes/1.1 and it keeps appending /en/ at the beginning of the url.
With this configuration on every other pages the dropdown is working.
I have been searching a lot on bug reports on your GitHub, on Stackoverflow and also on the Docusaurus documentation but I can't find why it's behaving like this.
Any ideas what could be causing the problem?
Thanks in advance for your help !!!
Expected behavior
if I set trailingSlash: false :
On the homepage, anytime the english button on the dropdown is clicked it would great to go to /user-doc/en/ and that the page /user-doc/en/ works
Actual behavior
if I set trailingSlash: false :
On the homepage, anytime the english button on the dropdown is clicked it tries to go to /user-doc/en/ but I have a status 302 and I am directly redirected to /user-doc/
Your environment
- Public source code: N/A
- Public site URL: N/A
- Docusaurus version used: 3.2.1
- Environment name and version (e.g. Chrome 89, Node.js 16.4): Node.js v20.9.0.
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): Ubuntu
Self-service
- I'd be willing to fix this bug myself.