From 812daa8af56510ed4beb008471b27f18a9f42d77 Mon Sep 17 00:00:00 2001 From: slorber Date: Wed, 3 Jun 2020 18:13:10 +0200 Subject: [PATCH] improve doc --- website/docs/using-plugins.md | 51 ++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/website/docs/using-plugins.md b/website/docs/using-plugins.md index 079797f1d1..a2a97ba5c2 100644 --- a/website/docs/using-plugins.md +++ b/website/docs/using-plugins.md @@ -513,7 +513,29 @@ module.exports = { For custom redirect logic, provide your own `createRedirects` function. -Let's imagine you change the url of an pexisting age, you might want to make sure the old url still works: +Let's imagine you change the url of an existing page, you might want to make sure the old url still works: + +```js title="docusaurus.config.js" +module.exports = { + plugins: [ + [ + '@docusaurus/plugin-client-redirects', + { + redirects: [ + { + // : string + to: '/docs/newDocPath', + // : string | string[] + from: ['/docs/oldDocPathFrom2019', '/docs/legacyDocPathFrom2016'], + }, + ], + }, + ], + ], +}; +``` + +It's possible to use a function to create the redirects for each existing path: ```js title="docusaurus.config.js" module.exports = { @@ -531,3 +553,30 @@ module.exports = { ], }; ``` + +Finally, it's possible to use all options at the same time: + +```js title="docusaurus.config.js" +module.exports = { + plugins: [ + [ + '@docusaurus/plugin-client-redirects', + { + fromExtensions: ['html', 'htm'], + toExtensions: ['exe', 'zip'], + redirects: [ + { + to: '/docs/newDocPath', + from: '/docs/oldDocPath', + }, + ], + createRedirects: function (existingPath) { + if (existingPath === '/docs/newDocPath2') { + return ['/docs/oldDocPath2']; + } + }, + }, + ], + ], +}; +```