Ir para o conteúdo principal
Version: 2.0.0-beta.15

📦 plugin-client-redirects

Plugin Docusaurus para gerar um redirecionamento do lado cliente.

This plugin will write additional HTML pages to your static site that redirect the user to your existing Docusaurus pages with JavaScript.

production only

This plugin is always inactive in development and only active in production because it works on the build output.

caution

É melhor usar redirecionamentos do servidor sempre que possível.

Antes de usar este plugin, você deve verificar se o seu provedor de hospedagem não oferece esta funcionalidade.

Instalação

npm install --save @docusaurus/plugin-client-redirects

Configuração

Campos aceitos:

OptionTypeDefaultDescription
fromExtensionsstring[][]The extensions to be removed from the route after redirecting.
toExtensionsstring[][]The extensions to be appended to the route after redirecting.
redirectsRedirectRule[][]The list of redirect rules.
createRedirectsCreateRedirectsFnundefinedA callback to create a redirect rule.
type RedirectRule = {
to: string;
from: string | string[];
};

type CreateRedirectsFn = (path: string) => string[] | string | null | undefined;

Configuração de exemplo

Here's an example configuration:

docusaurus.config.js
module.exports = {
plugins: [
[
'@docusaurus/plugin-client-redirects',
{
fromExtensions: ['html', 'htm'], // /myPage.html -> /myPage
toExtensions: ['exe', 'zip'], // /myAsset -> /myAsset.zip (if latter exists)
redirects: [
// /docs/oldDoc -> /docs/newDoc
{
to: '/docs/newDoc',
from: '/docs/oldDoc',
},
// Redirect from multiple old paths to the new path
{
to: '/docs/newDoc2',
from: ['/docs/oldDocFrom2019', '/docs/legacyDocFrom2016'],
},
],
createRedirects(existingPath) {
if (existingPath.includes('/community')) {
// Redirect from /docs/team/X to /community/X and /docs/support/X to /community/X
return [
existingPath.replace('/community', '/docs/team'),
existingPath.replace('/community', '/docs/support'),
];
}
return undefined; // Return a falsy value: no redirect created
},
},
],
],
};