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

๐Ÿ“ฆ plugin-client-redirects

ํด๋ผ์ด์–ธํŠธ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ๋„ํ์‚ฌ์šฐ๋ฃจ์Šค ํ”Œ๋Ÿฌ๊ทธ์ธ์ž…๋‹ˆ๋‹ค.

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

์ œํ’ˆ ๋นŒ๋“œ ์ „์šฉ

ํ•ด๋‹น ํ”Œ๋Ÿฌ๊ทธ์ธ์€ ๋นŒ๋“œ ์‚ฐ์ถœ๋ฌผ์—์„œ๋งŒ ์ž‘๋™ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฐœ๋ฐœ ์ค‘์—๋Š” ๋น„ํ™œ์„ฑํ™”๋˜๊ณ  ์ œํ’ˆ ๋นŒ๋“œ ์‹œ์—๋งŒ ํ™œ์„ฑํ™”๋ฉ๋‹ˆ๋‹ค.

์ฃผ์˜

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

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

์„ค์น˜โ€‹

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

์„ค์ •โ€‹

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

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

ํ”Œ๋Ÿฌ๊ทธ์ธ์—์„œ siteConfig.onDuplicateRoutes ์„ค์ •์„ ํ™•์ธํ•˜๊ณ  ์—ฌ๋Ÿฌ ํŒŒ์ผ์„ ๊ฐ™์€ ์œ„์น˜๋กœ ๋‚ด๋ณด๋‚ผ ๋•Œ ๋กœ๊น… ์ˆ˜์ค€์„ ์กฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

ํƒ€์ž…โ€‹

RedirectRuleโ€‹

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

"from"๊ณผ "to"์˜ ๊ฐœ๋…์€ ์ด ํ”Œ๋Ÿฌ๊ทธ์ธ์˜ ํ•ต์‹ฌ์ž…๋‹ˆ๋‹ค. "From"์€ ์ž‘์„ฑํ•˜๋ ค๋Š” ๊ฒฝ๋กœ, ์ฆ‰ ์ž‘์„ฑ๋  ์ถ”๊ฐ€ HTML ํŒŒ์ผ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. "to"๋Š” ๋ฆฌ๋‹ค์ด๋ ‰ํŠธํ•˜๋ ค๋Š” ๊ฒฝ๋กœ๋ฅผ ์˜๋ฏธํ•˜๋ฉฐ ์ผ๋ฐ˜์ ์œผ๋กœ ๋„ํ์‚ฌ์šฐ๋ฃจ์Šค๊ฐ€ ์ด๋ฏธ ์•Œ๊ณ  ์žˆ๋Š” ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.

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

CreateRedirectsFnโ€‹

// `path` ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ๋„ํ์‚ฌ์šฐ๋ฃจ์Šค๊ฐ€ ์ด๋ฏธ ์ƒ์„ฑํ•œ ๋ผ์šฐํŠธ์ž…๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ "to"์ด๋ฉฐ
// ๋ฐ˜ํ™˜๊ฐ’์€ "from"์ด ๋ฉ๋‹ˆ๋‹ค. ๊ฑฐ์ง“ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๋ฉด
// ํŠน์ • ๊ฒฝ๋กœ์— ๋Œ€ํ•œ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ํŽ˜์ด์ง€๊ฐ€ ์ƒ์„ฑ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
type CreateRedirectsFn = (path: string) => string[] | string | null | undefined;

์„ค์ • ์˜ˆ์‹œโ€‹

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

docusaurus.config.js
module.exports = {
plugins: [
[
'@docusaurus/plugin-client-redirects',
{
fromExtensions: ['html', 'htm'], // /myPage.html -> /myPage
toExtensions: ['exe', 'zip'], // /myAsset -> /myAsset.zip (ํ›„์ž๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ)
redirects: [
// /docs/oldDoc -> /docs/newDoc
{
to: '/docs/newDoc',
from: '/docs/oldDoc',
},
// ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ด์ „ ๊ฒฝ๋กœ์—์„œ ์ƒˆ๋กœ์šด ๊ฒฝ๋กœ๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ
{
to: '/docs/newDoc2',
from: ['/docs/oldDocFrom2019', '/docs/legacyDocFrom2016'],
},
],
createRedirects(existingPath) {
if (existingPath.includes('/community')) {
// /docs/team/X์—์„œ /community/X๋กœ ๊ทธ๋ฆฌ๊ณ  /docs/support/X์—์„œ /community/X๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ
return [
existingPath.replace('/community', '/docs/team'),
existingPath.replace('/community', '/docs/support'),
];
}
return undefined; // ์ž˜๋ชป๋œ ๊ฐ’ ๋ฐ˜ํ™˜: ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ๊ฐ€ ๋งŒ๋“ค์–ด์ง€์ง€ ์•Š์Œ
},
},
],
],
};