Docusaurus provides some APIs on the clients that can be helpful to you when building your site.
This reusable React component will manage all of your changes to the document head. It takes plain HTML tags and outputs plain HTML tags and is beginner-friendly. It is a wrapper around React Helmet.
Nested or latter components will override duplicate usages:
This component enables linking to internal pages as well as a powerful performance feature called preloading. Preloading is used to prefetch resources so that the resources are fetched by the time the user navigates with this component. We use an
IntersectionObserver to fetch a low-priority request when the
<Link> is in the viewport and then use an
onMouseOver event to trigger a high-priority request when it is likely that a user will navigate to the requested resource.
The component is a wrapper around react-router’s
<Link> component that adds useful enhancements specific to Docusaurus. All props are passed through to react-router’s
The target location to navigate to. Example:
<Redirect> will navigate to a new location. The new location will override the current location in the history stack, like server-side redirects (HTTP 3xx) do. You can refer to React Router's Redirect documentation for more info on available props.
@docusaurus/router implements React Router and supports its features.
<BrowserOnly> component accepts a
children prop, a render function which will not be executed during the pre-rendering phase of the build process. This is useful for hiding code that is only meant to run in the browsers (e.g. where the
document objects are being accessed). To improve SEO, you can also provide fallback content using the
fallback prop, which will be prerendered until in the build process and replaced with the client-side only contents when viewed in the browser.
A simple interpolation component for text containing dynamic placeholders.
The placeholders will be replaced with the provided dynamic values and JSX elements of your choice (strings, links, styled elements...).
children: text containing interpolation placeholders like
values: object containing interpolation placeholder values
The translation strings will be extracted from your code with the
docusaurus write-translations CLI and create a
code.json translation file in
<Translate/> props must be hardcoded strings.
values prop used for interpolation, it is not possible to use variables, or the static extraction wouldn't work.
children: untranslated string in the default site locale (can contain interpolation placeholders)
id: optional value to use as key in JSON translation files
description: optional text to help the translator
values: optional object containing interpolation placeholder values
React hook to access Docusaurus Context. Context contains
siteConfig object from docusaurus.config.js, and some additional site metadata.
React hook to prepend your site
baseUrl to a string.
Don't use it for regular links!
/baseUrl/ prefix is automatically added to all absolute paths by default:
[link](/my/path)will link to
<Link to="/my/path/">link</Link>will link to
In most cases, you don't need
require() call for assets:
useBaseUrl is not good enough. This hook return additional utils related to your site's base url.
withBaseUrl: useful if you need to add base urls to multiple urls at once.
React hook to access Docusaurus global data created by all the plugins.
Global data is namespaced by plugin name, and plugin id.
Plugin id is only useful when a plugin is used multiple times on the same site. Each plugin instance is able to create its own global data.
Inspect your site's global data at
Access global data created by a specific plugin instance.
This is the most convenient hook to access plugin global data, and should be used most of the time.
pluginId is optional if you don't use multi-instance plugins.
Access global data created by a specific plugin. Given a plugin name, it returns the data of all the plugins instances of that name, by plugin id.
The imperative counterpart of the
Use the imperative API for the rare cases where a component cannot be used, such as:
- the page
placeholderprops of form inputs
aria-labelprops for accessibility
A module which exposes a few boolean variables to check the current rendering environment. Useful if you want to only run certain code on client/server or need to write server-side rendering compatible code.
A module exposing useful constants to client-side theme code.