๋ฉ”์ธ ์ปจํ…์ธ ๋กœ ์ด๋™
๋ฒ„์ „: 3.6.2

๐Ÿ“ฆ plugin-client-redirects

Docusaurus Plugin to generate client-side redirects.

ํ”Œ๋Ÿฌ๊ทธ์ธ์—์„œ๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ๋งŒ๋“  ๋„ํ์‚ฌ์šฐ๋ฃจ์Šค ํŽ˜์ด์ง€๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธํ•  ์ˆ˜ ์žˆ๋„๋ก ์—ฌ๋Ÿฌ๋ถ„์˜ ์ •์ ์ธ ์‚ฌ์ดํŠธ์— HTML ํŽ˜์ด์ง€๋ฅผ ์ถ”๊ฐ€๋กœ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

production only

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

๊ฒฝ๊ณ 

๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ์„œ๋ฒ„ ์ธก ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.

ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์ „์— ์—ฌ๋Ÿฌ๋ถ„์˜ ํ˜ธ์ŠคํŠธ ์„œ๋น„์Šค ์—…์ฒด๊ฒŒ ์ด ๊ธฐ๋Šฅ์„ ์ง€์›ํ•˜์ง€ ์•Š๋Š”์ง€ ๋จผ์ € ํ™•์ธํ•ด๋ณด์„ธ์š”.

Installationโ€‹

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

Configurationโ€‹

์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š” ํ•„๋“œ

์˜ต์…˜ํƒ€์ž…๊ธฐ๋ณธ๊ฐ’์„ค๋ช…
fromExtensionsstring[][]๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ํ›„ ๊ฒฝ๋กœ์—์„œ ์ œ๊ฑฐํ•  ํ™•์žฅ์ž์ž…๋‹ˆ๋‹ค.
toExtensionsstring[][]๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ํ›„ ๊ฒฝ๋กœ์— ์ถ”๊ฐ€ํ•  ํ™•์žฅ์ž์ž…๋‹ˆ๋‹ค.
redirectsRedirectRule[][]๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ๊ทœ์น™ ๋ชฉ๋ก์ž…๋‹ˆ๋‹ค.
createRedirectsCreateRedirectsFnundefined๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ๊ทœ์น™์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•œ ์ฝœ๋ฐฑ์ž…๋‹ˆ๋‹ค. ๋„ํ์‚ฌ์šฐ๋ฃจ์Šค๋Š” ์ƒ์„ฑํ•œ ๋ชจ๋“  ๊ฒฝ๋กœ์— ๋Œ€ํ•ด ์ฝœ๋ฐฑ์„ ์š”์ฒญํ•˜๊ณ  ๋ฐ˜ํ™˜๊ฐ’์„ ์‚ฌ์šฉํ•ด ๋” ๋งŽ์€ ๊ฒฝ๋กœ๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.
์ฐธ๊ณ 

This plugin will also read the siteConfig.onDuplicateRoutes config to adjust its logging level when multiple files will be emitted to the same location.

Typesโ€‹

RedirectRuleโ€‹

type RedirectRule = {
to: string;
from: string | string[];
};
์ฐธ๊ณ 

"from"๊ณผ "to"์˜ ๊ฐœ๋…์€ ์ด ํ”Œ๋Ÿฌ๊ทธ์ธ์˜ ํ•ต์‹ฌ์ž…๋‹ˆ๋‹ค. "From" means a path that you want to create, i.e. an extra HTML file that will be written; "to" means a path to want to redirect to, usually a route that Docusaurus already knows about.

์ด ๋•Œ๋ฌธ์— ๊ฐ™์€ "to"์— ๋Œ€ํ•ด ์—ฌ๋Ÿฌ ๊ฐœ์˜ "from"์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ชจ๋‘ ๊ฐ™์€ ๋ชฉ์ ์ง€๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ๋˜๋Š” ์—ฌ๋Ÿฌ ๊ฐœ์˜ HTML ํŒŒ์ผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๋ฐ˜๋ฉด์— "from"์€ ํ•˜๋‚˜๋ณด๋‹ค ๋งŽ์€ "to"๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ์ž‘์„ฑ๋œ HTML ํŒŒ์ผ์€ ๋ช…ํ™•ํ•œ ๋ชฉ์ ์ง€๊ฐ€ ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

CreateRedirectsFnโ€‹

// The parameter `path` is a route that Docusaurus has already created. It can
// be seen as the "to", and your return value is the "from". Returning a falsy
// value will not create any redirect pages for this particular path.
type CreateRedirectsFn = (path: string) => string[] | string | null | undefined;

Example configurationโ€‹

๋‹ค์Œ์€ ์„ค์ • ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค:

docusaurus.config.js
export default {
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
},
},
],
],
};