๐ฆ plugin-client-redirects
ํด๋ผ์ด์ธํธ ์ธก ๋ฆฌ๋๋ ์ ์ ์์ฑํ๋ ๋ํ์ฌ์ฐ๋ฃจ์ค ํ๋ฌ๊ทธ์ธ์ ๋๋ค.
ํ๋ฌ๊ทธ์ธ์์๋ ์๋ฐ์คํฌ๋ฆฝํธ๋ก ๋ง๋ ๋ํ์ฌ์ฐ๋ฃจ์ค ํ์ด์ง๋ก ๋ฆฌ๋ค์ด๋ ํธํ ์ ์๋๋ก ์ฌ๋ฌ๋ถ์ ์ ์ ์ธ ์ฌ์ดํธ์ HTML ํ์ด์ง๋ฅผ ์ถ๊ฐ๋ก ๋ง๋ญ๋๋ค.
์ด ํ๋ฌ๊ทธ์ธ์ ๋น๋ ๊ฒฐ๊ณผ๋ฌผ์ ๋์์ผ๋ก ๋์ํ๋ฏ๋ก ๊ฐ๋ฐ ํ๊ฒฝ์์๋ ํญ์ ๋นํ์ฑํ๋๋ฉฐ ํ๋ก๋์ ์์๋ง ํ์ฑํ๋ฉ๋๋ค.
๊ฐ๋ฅํ๋ค๋ฉด ์๋ฒ ์ธก ๋ฆฌ๋ค์ด๋ ํธ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ๊ถ์ฅํฉ๋๋ค.
ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉํ๊ธฐ ์ ์ ์ฌ๋ฌ๋ถ์ ํธ์คํธ ์๋น์ค ์ ์ฒด๊ฒ ์ด ๊ธฐ๋ฅ์ ์ง์ํ์ง ์๋์ง ๋จผ์ ํ์ธํด๋ณด์ธ์.
์ค์นโ
- npm
- Yarn
- pnpm
- Bun
npm install --save @docusaurus/plugin-client-redirects
yarn add @docusaurus/plugin-client-redirects
pnpm add @docusaurus/plugin-client-redirects
bun add @docusaurus/plugin-client-redirects
์ค์ โ
์ค์ ํ ์ ์๋ ํ๋
| ์ต์ | ํ์ | ๊ธฐ๋ณธ๊ฐ | ์ค๋ช |
|---|---|---|---|
fromExtensions | string[] | [] | ๋ฆฌ๋ค์ด๋ ํธ ํ ๊ฒฝ๋ก์์ ์ ๊ฑฐํ ํ์ฅ์์ ๋๋ค. |
toExtensions | string[] | [] | ๋ฆฌ๋ค์ด๋ ํธ ํ ๊ฒฝ๋ก์ ์ถ๊ฐํ ํ์ฅ์์ ๋๋ค. |
redirects | RedirectRule[] | [] | ๋ฆฌ๋ค์ด๋ ํธ ๊ท์น ๋ชฉ๋ก์ ๋๋ค. |
createRedirects | CreateRedirectsFn | undefined | ๋ฆฌ๋ค์ด๋ ํธ ๊ท์น์ ๋ง๋ค๊ธฐ ์ํ ์ฝ๋ฐฑ์ ๋๋ค. ๋ํ์ฌ์ฐ๋ฃจ์ค๋ ์์ฑํ ๋ชจ๋ ๊ฒฝ๋ก์ ๋ํด ์ฝ๋ฐฑ์ ์์ฒญํ๊ณ ๋ฐํ๊ฐ์ ์ฌ์ฉํด ๋ ๋ง์ ๊ฒฝ๋ก๋ฅผ ์ถ๋ ฅํฉ๋๋ค. |
์ด ํ๋ฌ๊ทธ์ธ์ ์ฌ๋ฌ ํ์ผ์ด ๊ฐ์ ์์น์ ์์ฑ๋ ๋ ๋ก๊ทธ ์์ค์ ์กฐ์ ํ๊ธฐ ์ํด 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"์ ํด๋นํฉ๋๋ค. falsy ๊ฐ์ ๋ฐํํ๋ฉด ์ด ๊ฒฝ๋ก์ ๋ํ
// ๋ฆฌ๋๋ ์
ํ์ด์ง๋ฅผ ์์ฑํ์ง ์์ต๋๋ค.
type CreateRedirectsFn = (path: string) => string[] | string | null | undefined;
์ค์ ์์โ
๋ค์์ ์ค์ ์์์ ๋๋ค:
export default {
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์ /docs/support/X์์ /community/X๋ก ๋ฆฌ๋๋ ์
return [
existingPath.replace('/community', '/docs/team'),
existingPath.replace('/community', '/docs/support'),
];
}
return undefined; // falsy ๊ฐ์ ๋ฐํํ๋ฉด ๋ฆฌ๋๋ ์
์ ์์ฑํ์ง ์์ต๋๋ค
},
},
],
],
};