Rspress exposes some runtime APIs, which is convenient for you to do some custom logic.
() => PageData
Get the data of the current page, and the return value is an object, which contains all the data of the current page.
() => string
Get the current language, the return value is a string, which is the current language.
() => string
Get the current version, the return value is a string, which is the current version.
() => boolean
Whether it is dark mode currently, the return value is a boolean value.
Note that in the SSG process, useDark
cannot accurately reflect the theme setting of the user's browser, because SSG is executed during the build stage. Only after client hydration is complete, this hook will return the correct theme value.
If you need to apply a dark theme style in the SSG stage, it is recommended to use the CSS selector .dark
to set the style. Rspress will add the dark
class name to the root element of the document, which will be effective in both SSG and client:
The framework provides useI18n
this hook to get the internationalized text, the usage is as follows:
For better type hinting, you can configure paths
in tsconfig.json:
Then use it like this in the component:
This way you get type hints for all literal keys defined in i18n.json
.
See more in Internationalization.
Rspress internally uses and re-exports all APIs of react-router-dom
, you can use it like this: