facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
56.94k stars 8.57k forks source link

Make routing `basename` configurable #4712

Closed ilteoood closed 3 years ago

ilteoood commented 3 years ago

🚀 Feature

I would like to include docusaurus using a micro-frontend framework like qiankun or single-spa: to do this, I need to configure the basename property for the BrowserRouter in clientEntry.js.

Should be awesome if this could be configured using the window object.

Have you read the Contributing Guidelines on issues?

Yes

Motivation

Make docusaurus be available as micro frontend.

Pitch

This should be implemented in order to customize the routing basename, which isn't always / for micro frontends.

slorber commented 3 years ago

We don't use React-Router basename, but we support baseUrl in config to enable you to use host your Docusaurus SPA under a subpath: https://docusaurus.io/docs/next/docusaurus.config.js#baseurl

You can provide a custom baseurl by using an env variable in the config file.

It is not possible to use the window object to configure the baseUrl/basename, as the window object is not available during server rendering. We absolutely need the client/server config to be in sync, otherwise the URL of your links would change only after React was hydrated. We really don't want that to happen, as a Docusaurus link must work even when js fails to load or when JS is disabled.