pages/_document.js > components/Document.js
pages/_error.js > components/Error.js
์์ ์ด๋ ๊ฒ๋ _pages_๊ฐ ์๋๋ฉฐ ํน๋ณํ _components_์
๋๋ค. ๋ชจ๋ ์ฌ๋์ด pages
์์ $ components
ํด๋๋ฅผ ๊ฐ๋ ๊ท์น์ ์ฑํํ๊ธฐ ๋๋ฌธ์ ํด๋๋ฅผ ์ฌ๊ธฐ๋ก ์ฎ๊ธฐ๊ณ ์ฌ์ฉ๋๋ _reserved_ ๊ตฌ์ฑ ์์ ์ด๋ฆ์์ ๋ฌธ์ํํ๋ ๊ฒ์ด ํจ์ฌ ๋ ๋ฉ์ง๊ณ "๋ ์ ํํ" IMO๊ฐ ๋ ๊ฒ์
๋๋ค. ๋ค์์ผ๋ก.
pages
์์ _๋ชจ๋ _ JS ํ์ผ์ ์ฝ์ ์ ์๊ณ ์ด๋ฌํ ํน๋ณํ ๊ฒฝ์ฐ๋ฅผ ๊ฑธ๋ฌ๋ผ ํ์๊ฐ ์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ด ๋ ๊น๋ํ๊ณ ์ฝ๋ ๋ถํ ๋ฐ ๋ฒ๋ค๋ง ๋
ผ๋ฆฌ๋ฅผ ๋จ์ํํ ๊ฒ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค. ๊ทธ๊ฒ์ ๋ํ file์ด๋ผ๋ ์ด๋ฆ์ ์ฝ๊ฐ ๋ชป์๊ธด ๋ฐ์ค์ ๊ทผ์ ํ ๊ฒ์
๋๋ค...๊ทธ๊ฑด ์ ์๊ฐ์ผ ๋ฟ์
๋๋ค!
๊ฐ์ฌ ํด์. ๋น์ ์ ์ ํจํ ํฌ์ธํธ๋ฅผ ์ป์๋ค.
๊ทธ๋ฌ๋ ๋จ๊ธฐ์ ์ผ๋ก๋ ๊ทธ๊ฒ์ ๋ฐ๊พธ์ง ์์ ๊ฒ์
๋๋ค.
2.0.0
๊ฐ ๊ณง ์ถ์๋๋ ๋งํผ, ์ด๋ฐ ๋ธ๋ ์ดํน ์ฒด์ธ์ง๋ฅผ ์๊ฐํ ์ ์๋ ์ข์ ๊ธฐํ๊ฐ ๋์ง ์์๊น ์๊ฐํ์ต๋๋ค. ๋ ์ต์
์ ๋ชจ๋ ์ง์ํ๊ณ pages/_document.js
๋ฐ pages/_error.js
๋ฅผ ์ฌ์ฉํ๋ ์ฌ์ฉ์์๊ฒ ๊ฒฝ๊ณ ๋ฅผ ๊ธฐ๋กํ๊ณ ํ์ผ์ ์ด๋ํ๊ณ ์ด๋ฆ์ ๋ฐ๊พธ๋ผ๊ณ ์กฐ์ธํ ์ ์์ต๋๊น? ๊ทธ๋ ๊ฒ ํ๋ฉด ์๋ฌด ๊ฒ๋ ๊นจ์ง์ง ์๊ณ ์ฌ๋๋ค์ด ์ด์ฃผํ ์ ์์ต๋๋ค.
์ด PR https://github.com/zeit/next.js/pull/936 ์ ๋ฐฉ๊ธ ์ฝ์์ผ๋ฏ๋ก ์ด ์ ์์ pagesDirectory
next.config.js
๊ฐ์ฒด์์๋ ์ฒ๋ฆฌ๋ ์ ์์ต๋๋ค.
documentComponent
๋ฐ errorComponent
$ ์ ๊ฐ์ ๋ ๋ค๋ฅธ ๋ช ๊ฐ์ง ์ํ์ ์ ๋ฌํ ์ ์์ต๋๋ค.
// next.config.js
module.exports = {
pagesDirectory: 'views',
documentComponent: 'components/Document.js',
errorComponent: 'components/Error.js'
}
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด PR https://github.com/zeit/next.js/pull/936 ์ ๋ฐฉ๊ธ ์ฝ์์ผ๋ฏ๋ก ์ด ์ ์์
pagesDirectory
next.config.js
๊ฐ์ฒด์์๋ ์ฒ๋ฆฌ๋ ์ ์์ต๋๋ค.documentComponent
๋ฐerrorComponent
$ ์ ๊ฐ์ ๋ ๋ค๋ฅธ ๋ช ๊ฐ์ง ์ํ์ ์ ๋ฌํ ์ ์์ต๋๋ค.