-
Notifications
You must be signed in to change notification settings - Fork 5
web_trouble_shooting
sang-gyeong lee edited this page Dec 20, 2020
·
1 revision
-> Next.js ๊ณต์๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์ฌ _document.tsx ํ์ผ์ ์ปค์คํ ํ์ฌ ํด๊ฒฐํจ
๋ฃจํธ ํ์ผ์ .babelrc ํ์ผ ๋ง๋ค๊ธฐ
{
"presets": [
"next/babel"
],
"plugins": [
[
"styled-components",
{
"ssr": true,
"displayName": true,
"preprocess": false
}
]
]
}
Create the _document.js file pages ํด๋ ์๋์ _document.js ์์ฑ
import Document, { Head, Main, NextScript } from 'next/document';
// Import styled components ServerStyleSheet
import { ServerStyleSheet } from 'styled-components';
export default class MyDocument extends Document {
static getInitialProps({ renderPage }) {
// Step 1: Create an instance of ServerStyleSheet
const sheet = new ServerStyleSheet();
// Step 2: Retrieve styles from components in the page
const page = renderPage((App) => (props) =>
sheet.collectStyles(<App {...props} />),
);
// Step 3: Extract the styles as <style> tags
const styleTags = sheet.getStyleElement();
// Step 4: Pass styleTags as a prop
return { ...page, styleTags };
}
render() {
return (
<html>
<Head>
<title>My page</title>
{/* Step 5: Output the styles in the head */}
{this.props.styleTags}
</Head>
<body>
<Main />
<NextScript />
</body>
</html>
);
}
}
์ฐธ๊ณ https://dev.to/aprietof/nextjs--styled-components-the-really-simple-guide----101c
- ๋ฌธ์ ์ํฉ : ์ํธ๋ฆฌ ํ์ผ์์ switch route ๋ถ๊ธฐ์ฒ๋ฆฌ ๋ถ๋ถ์์ ๋ก์ปฌ์คํ ๋ฆฌ์ง์ ์ฟ ํค์ ์ ๊ทผํ์ฌ ์ ์ ์ ๋ก๊ทธ์ธ ์ฌ๋ถ๋ฅผ ํ๋ณํ์๋
๊ธฐ์กด์ ๋ฆฌ์กํธ ํ๋ก์ ํธ์ ๋ฌ๋ฆฌ, next.js์์ ์ฟ ํค ๋ฐ ๋ก์ปฌ ์คํฐ๋ฆฌ์ง์ ์ ๊ทผํ๋ ๋ฐฉ๋ฒ์ ์ฐพ์ง ๋ชปํด ์ด๋ ค์์ ๊ฒช์๋ค.- getServersideProps๋ฅผ ์ฌ์ฉํ์ฌ req.headers.cookie๋ก ์ฟ ํค์ ์ ๊ทผํ๋ ๊ฒ์ ์ฑ๊ณตํ์๋ค.
- ์๋ฒ์์ ์ป์ ์ฟ ํค๋ฅผ ํด๋ผ์ด์ธํธ์ ๋๊ฒจ์ฃผ๊ณ , api.default.headers.authorization์ ํด๋น ์ฟ ํค๋ฅผ ๋ฃ๋ ๋ฐฉ๋ฒ์ผ๋ก ํค๋์ ์ฟ ํค๋ฅผ ๋ฃ์ ์ ์์๋ค.
- ๋ฌธ์ ์ํฉ : iOS ํ๊ณผ์ ํ์
์ค, iPad๋ฅผ user-agent์์ ๊ตฌ๋ถํ์ง ๋ชปํ๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์๋ค.
- iPad๊ฐ ๋ฒ์ ์ ๋ฐ์ดํธ ๋๋ฉด์ ์น๊ณผ ๊ฑฐ์ ์ ์ฌํ uger-agent๋ฅผ ๋ณด์๊ธฐ ๋๋ฌธ์ ๋ถ๊ธฐ์ฒ๋ฆฌ์ ์ด๋ ค์์ ๋๊ผ๋ค.
- ๊ฒฐ๊ตญ auth2๋ผ๋ ์๋ก์ด API๋ฅผ ๋ง๋ค์ด ๋ชจ๋ฐ์ผ ํ์ ์ ๋ฌํจ์ผ๋ก์จ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์๋ค.
โ 2020. Project01-C-User-Event-Collector [J028_๊น๋๊ท , J089_๋ฐ์งํ, J139_์ด์๊ฒฝ, S059_์ต๊ดํ, S060_์ต๋๊ท] all rights reserved.