Just keep coding ...๐Ÿ’–โœŒ๏ธ

[Next.js] (3) - Page Router (๊ทธ๋ฆฌ๊ณ  Next ๊ธฐ๋ณธ๋™์ž‘๊ตฌ์กฐ)

2024. 11. 4. 07:11ใ†front-end/Next.js

728x90

๐Ÿ‘‰  Page Router

  • ํ˜„์žฌ ๋งŽ์€ ๊ธฐ์—…์—์„œ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋Š” ์•ˆ์ •์ ์ธ ๋ผ์šฐํ„ฐ
  • React Router ์ฒ˜๋Ÿผ ํŽ˜์ด์ง€ ๋ผ์šฐํŒ… ๊ธฐ๋Šฅ์„ ์ œ๊ณต

 

 

๐Ÿ‘‰  ํ”„๋ฆฌํŽ˜์นญ(Pre-fetching) - ๋น ๋ฅธ ํŽ˜์ด์ง€ ์ด๋™์„ ์œ„ํ•ด ์ œ๊ณต๋˜๋Š” ๊ธฐ๋Šฅ!

  • ์ด๋™ํ•  ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๋Š” ํŽ˜์ด์ง€๋ฅผ ๋ฏธ๋ฆฌ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๊ธฐ๋Šฅ

  • ๊ฒฝ๋กœ๋ณ„๋กœ ์ปดํฌ๋„ŒํŠธ๋“ค์„ Spliting ํ•ด์„œ ์ €์žฅ์„ ๋ฏธ๋ฆฌ ํ•ด๋†“์Œ 

  • ํ˜„์žฌ ํŽ˜์ด์ง€์—๋งŒ ํ•„์š”ํ•œ JS Bundle๋งŒ ์ „๋‹ฌ ๋จ

  • ์š”์ฒญ๋œ ํŽ˜์ด์ง€์˜ JS Bundle ๋งŒ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ ๋•Œ๋ฌธ์— Hydration ๋น ๋ฅด๊ฒŒ ๊ฐ€๋Šฅ (์šฉ๋Ÿ‰ ๊ฒฝ๋Ÿ‰ํ™”)
  • Pre Feching ์œผ๋กœ ์—ฐ๊ฒฐ๋œ ๋ชจ๋“  ํŽ˜์ด์ง€์˜ JS Bundle ํŒŒ์ผ์„ ๋ฏธ๋ฆฌ ๋ถˆ๋Ÿฌ์˜ด

  • ๊ฐœ๋ฐœ๋ชจ๋“œ์ผ ๊ฒฝ์šฐ์—๋Š” Pre Feching์ด ์ ์šฉ๋˜์ง€ ์•Š์Œ Build ํ›„ production ๋ชจ๋“œ๋กœ ์‹คํ–‰ํ•ด์ค˜์•ผํ•จ
  • Link Component๋กœ ์ด๋ค„์ง€์ง€ ์•Š์€ ๊ฒฝ์šฐ,  Pre Fetching ์ด ์ด๋ค„์ง€์ง€ ์•Š์Œ
  • Programmatic ํ•˜๊ฒŒ Pre Fetching ์„ ํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ router ๊ฐ์ฒด์˜ prefetch ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•จ
  const onClickButton = () => {
    router.push('/test')
  }

  //mount ๋  ๋•Œ๋งŒ ํ•œ ๋ฒˆ ์‹คํ–‰
  useEffect(() => {
    router.prefetch('/test')
  }, [])
  • Pre Fetching ์„ ๋ช…์‹œ์ ์œผ๋กœ ํ•ด์ œํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ
<Link href="/search" prefetch={false}>
  search
</Link>

 

๐Ÿ‘‰ API Routes - API๋ฅผ ๊ตฌ์ถ•ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ๊ธฐ๋Šฅ

export default function handler(req: NextApiRequest, res: NextApiResponse) {
  const date = new Date()
  res.json({ time: date.toLocaleDateString() })
}

 

 

 

 

 

 

Next.js ๊ธฐ์ดˆ๊ฐ•์˜ ๋งค์šฐ ์ถ”์ฒœ : ) 

 

์ถœ์ฒ˜: https://www.inflearn.com/course/%ED%95%9C%EC%9E%85-%ED%81%AC%EA%B8%B0-nextjs/dashboard

 

ํ•œ ์ž… ํฌ๊ธฐ๋กœ ์ž˜๋ผ๋จน๋Š” Next.js(15+) ๊ฐ•์˜ | ์ด์ •ํ™˜ Winterlood - ์ธํ”„๋Ÿฐ

์ด์ •ํ™˜ Winterlood | ํ•œ์ž… ์‹œ๋ฆฌ์ฆˆ์˜ 3๋ฒˆ์งธ ์ž‘ํ’ˆ! ์„ธ์ƒ์—์„œ ๊ฐ€์žฅ ์นœ์ ˆํ•˜๊ณ  ๋””ํ…Œ์ผ ํ•œ Next.js(15+)๊ฐ•์˜ ์ž…๋‹ˆ๋‹ค. App Router ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ Page Router๊นŒ์ง€ ํ”„๋กœ์ ํŠธ๋ฅผ ํ†ตํ•ด ์‚ดํŽด๋ด…๋‹ˆ๋‹ค., [์ž„๋ฒ ๋”ฉ ์˜์ƒ]ํ•œ ์ž… ํฌ๊ธฐ

www.inflearn.com

 

728x90