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

How can docusaurus' 404 page be adapted to other language pages? #10473

Open
1 of 2 tasks
Fei927 opened this issue Sep 3, 2024 · 6 comments
Open
1 of 2 tasks

How can docusaurus' 404 page be adapted to other language pages? #10473

Fei927 opened this issue Sep 3, 2024 · 6 comments
Labels
documentation The issue is related to the documentation of Docusaurus

Comments

@Fei927
Copy link

Fei927 commented Sep 3, 2024

Have you read the Contributing Guidelines on issues?

Description

How can docusaurus' 404 page be adapted to other language pages?

When I switch to other languages, such as French, I find that the 404 page cannot be switched to French, and the language switch box does not respond. Is there any way to make the 404 page change with the language switch?

Self-service

  • I'd be willing to address this documentation request myself.
@Fei927 Fei927 added documentation The issue is related to the documentation of Docusaurus status: needs triage This issue has not been triaged by maintainers labels Sep 3, 2024
@Josh-Cena
Copy link
Collaborator

Which 404 page gets served depends on your server. Most servers send /404.html whenever they receive a request to a nonexistent route. If you want to make it serve /fr/404.html, you have to configure your server to redirect all /fr/* to /fr/404.html. For example, check out https://github.com/facebook/docusaurus/blob/main/website/static/_redirects. This is going to be different for each server.

Maybe we can add this to the docs.

@slorber slorber removed the status: needs triage This issue has not been triaged by maintainers label Sep 3, 2024
@Fei927
Copy link
Author

Fei927 commented Sep 4, 2024

Which 404 page gets served depends on your server. Most servers send /404.html whenever they receive a request to a nonexistent route. If you want to make it serve /fr/404.html, you have to configure your server to redirect all /fr/* to /fr/404.html. For example, check out https://github.com/facebook/docusaurus/blob/main/website/static/_redirects. This is going to be different for each server.

Maybe we can add this to the docs.

What should I do if I don't use a hosting service?

@Josh-Cena
Copy link
Collaborator

What are you using?

@Fei927
Copy link
Author

Fei927 commented Sep 4, 2024

What are you using?

I deployed docusaurus directly on my local machine without using a web hosting service.

@slorber
Copy link
Collaborator

slorber commented Sep 4, 2024

Yes we should document this. Not easy though because we can't write a full guide to all the existing hosting platforms. But we can give a few generic hosting recommendations.

I also want to give a few tips like setting caching headers for assets, leveraging Webpack persistent caching etc... Not sure where to put that, the deployment page is already quite messy and long. Maybe we need a whole sidebar category just for deployment?


I deployed docusaurus directly on my local machine without using a web hosting service.

What does "deployed" mean, you must be running something on your local machine. docusaurus serve CLI is a possibility but there are many others including Apache, Nginx, arnish, http-server, serve...

You should read the doc of the tool you use, and see if it's possible to redirect 404 reponses to the /<locale>/404.html file.


Note that docusaurus serve is not particularly the best option, as we document here: https://docusaurus.io/docs/deployment#self-hosting

I don't think we expose any way to serve the localized 404 page, but that could be an interesting thing to add automatically. This is the lib we use under the hood and it supports rewrites: https://github.com/vercel/serve-handler


If you use something else, you'd have to figure it out because we don't provide support for anything else than docusaurus serve.

@Fei927
Copy link
Author

Fei927 commented Sep 5, 2024

Yes we should document this. Not easy though because we can't write a full guide to all the existing hosting platforms. But we can give a few generic hosting recommendations.

I also want to give a few tips like setting caching headers for assets, leveraging Webpack persistent caching etc... Not sure where to put that, the deployment page is already quite messy and long. Maybe we need a whole sidebar category just for deployment?

I deployed docusaurus directly on my local machine without using a web hosting service.

What does "deployed" mean, you must be running something on your local machine. docusaurus serve CLI is a possibility but there are many others including Apache, Nginx, arnish, http-server, serve...

You should read the doc of the tool you use, and see if it's possible to redirect 404 reponses to the /<locale>/404.html file.

Note that docusaurus serve is not particularly the best option, as we document here: https://docusaurus.io/docs/deployment#self-hosting

I don't think we expose any way to serve the localized 404 page, but that could be an interesting thing to add automatically. This is the lib we use under the hood and it supports rewrites: https://github.com/vercel/serve-handler

If you use something else, you'd have to figure it out because we don't provide support for anything else than docusaurus serve.

OK, I understand. I use docusaurus serve. I will follow your advice and adjust my website according to the deployment section in the document. Thank you!

Maybe you can consider adding why you need a hosting service and the advantages of using a hosting service in the deployment document. This is just a suggestion.

Thanks for your reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation The issue is related to the documentation of Docusaurus
Projects
None yet
Development

No branches or pull requests

3 participants