[Next.js] (4) - App Router

2024. 11. 1. 08:45ใ†front-end/Next.js

728x90

๐Ÿ‘‰  Dynamic Routing

  • ์—ฌ๋Ÿฌ๊ฐœ์˜ URL ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋„ฃ์„ ๋•Œ [...id] Catch all segment
  • ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์—†์„ ๊ฒฝ์šฐ์— [[...id]] Optional catch all segment

๐Ÿ‘‰  Layout ๋™์ž‘ ๋ฐฉ์‹

 

  • Layout ์•ˆ์— chlidren ์œผ๋กœ page ๊ฐ€ ๋“ค์–ด์žˆ์Œ  
  • Layout ์ด ์œ„ ์•„๋ž˜๋กœ ์žˆ์„ ๊ฒฝ์šฐ ์ค‘์ฒฉ๋จ

๐Ÿ‘‰  Route Group (์†Œ๊ด„ํ˜ธ๋กœ ์ž‘์„ฑ) 

  • ๊ฒฝ๋กœ์ƒ์—๋Š” ์•„๋ฌด๋Ÿฐ ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š์Œ
  • ๊ฐ๊ธฐ ๋‹ค๋ฅธ ๊ฒฝ๋กœ๋“ค์„ ํ•˜๋‚˜์˜ ํŽ˜์ด์ง€๋กœ ๋ฌถ์–ด๋‘˜ ์ˆ˜ ์žˆ์Œ
  • ๊ฒฝ๋กœ๊ฐ€ ๋‹ฌ๋ผ๋„ ๊ณตํ†ต์ ์ธ layout์„ ์ ์šฉํ•˜๊ณ  ์‹ถ์„ ๋•Œ

๐Ÿ‘‰  React Server Component (React 18v ๋ถ€ํ„ฐ, ์ƒˆ๋กœ์šด ์œ ํ˜•์˜ ์„œ๋ฒ„์ธก ์ปดํฌ๋„ŒํŠธ )

  • Page Router ๋ฒ„์ „์˜ Next.js ์—๋Š” ์–ด๋–ค ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ์„๊นŒ?
    • ์ •์  ํŽ˜์ด์ง€ ์ปดํฌ๋„ŒํŠธ๋Š” Hydration ์„ ํ•„์š”๋กœ ํ•˜์ง€ ์•Š์Œ
    • ๊ตณ์ด ๋ธŒ๋ผ์šฐ์ €์ธก์—์„œ ํ•œ ๋ฒˆ ๋” ์‹คํ–‰ํ•  ํ•„์š”๊ฐ€ ์—†์—ˆ์Œ
    • ๋ถˆํ•„์š”ํ•˜๊ฒŒ JS๋ฒˆ๋“ค๋กœ ๋ฌถ์—ฌ์„œ JS๋ฒˆ๋“ค ํฌ๊ธฐ๊ฐ€ ๋„ˆ๋ฌด ์ปค์ง
    • JS Bundle Size ์ปค์ง -> Hydration ์„ ๋งŽ์ด ํ•ด์•ผํ•ด์„œ ์†๋„๊ฐ€ ๋Š๋ ค์ง -> TTI ๊นŒ์ง€ ๋Šฆ์–ด์ง

  • ์ƒํ˜ธ์ž‘์šฉ์ด ์—†๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ํด๋ผ์ด์–ธํŠธ์ธก์— ์ „๋‹ฌ๋˜์ง€ ์•Š๋„๋ก ๋‹ค๋ฅธ ์œ ํ˜•์œผ๋กœ ๋ถ„๋ฆฌ
  • Next ์„œ๋ฒ„์ธก์—์„œ ์‚ฌ์ „๋ Œ๋”๋ง ํ•  ๋•Œ๋งŒ UI ๋ Œ๋”๋ง์ด ํ•œ ๋ฒˆ๋งŒ ์‹คํ–‰ ๋˜๋„๋ก!
  • ์„œ๋ฒ„์ธก์—์„œ๋งŒ ์‹คํ–‰๋˜๋Š” ์ปดํฌ๋„ŒํŠธ
  • ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋Š” ์ด 2๋ฒˆ ์‹คํ–‰ (์„œ๋ฒ„, ํด๋ผ์ด์–ธํŠธ ๋ชจ๋‘ ์‹คํ–‰)
    • ์‚ฌ์ „ ๋ Œ๋”๋ง ์„œ๋ฒ„์—์„œ 1๋ฒˆ ์‹คํ–‰ (์„œ๋ฒ„ ์ธก) 
    • JS ๋ฒˆ๋“ค ํ›„ ํ•˜์ด๋“œ๋ ˆ์ด์…˜ ํ•  ๋•Œ ๋ธŒ๋ผ์šฐ์ €์—์„œ 1๋ฒˆ ์‹คํ–‰ (ํด๋ผ์ด์–ธํŠธ ์ธก) 

  • JS ๋ฒˆ๋“ค์—๋Š” ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋งŒ ํฌํ•จ (์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ ์ œ์™ธ)
  • ํŽ˜์ด์ง€ ๋Œ€๋ถ€๋ถ„์„ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋กœ ๊ตฌ์„ฑํ•  ๊ฒƒ์„ ๊ถŒ์žฅ
  • ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋Š” ๊ผญ ํ•„์š”ํ•œ ๊ฒฝ์šฐ์—๋งŒ ์‚ฌ์šฉ
  • ๋ธŒ๋ผ์šฐ์ € ์ธก์—์„œ๋งŒ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ React Hooks๋Š” ์‚ฌ์šฉ ๋ถˆ๊ฐ€๋Šฅ

 

  • ์ƒํ˜ธ์ž‘์šฉ์ด ์žˆ์œผ๋ฉด ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ
  • ์ƒํ˜ธ์ž‘์šฉ์ด ์—†์œผ๋ฉด ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ
    • ๋งํฌ๋Š” HTML ๊ณ ์œ  ์ฝ”๋“œ

 

 

๐Ÿ‘‰   React Server Component ์ฃผ ์˜ ์‚ฌ ํ•ญ

  • ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ์—๋Š” ๋ธŒ๋ผ์šฐ์ €์—์„œ ์‹คํ–‰๋  ์ฝ”๋“œ๊ฐ€ ํฌํ•จ๋˜๋ฉด ์•ˆ๋จ
    • ๋ธŒ๋ผ์šฐ์ € ์ฝ”๋“œ๊ฐ€ ๋‹ด๊ฒจ์žˆ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋„ ์—๋Ÿฌ๋‚  ์ˆ˜ ์žˆ์Œ(์ฃผ์˜)
  • ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์—๋Š” ํด๋ผ์ด์–ธํŠธ์—์„œ๋งŒ ์‹คํ–‰๋˜์ง€ ์•Š์Œ
  • ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์—์„œ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋ฅผ import ํ•  ์ˆ˜ ์—†์Œ
  • ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ์—์„œ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์—๊ฒŒ ์ง๋ ฌํ™” ๋˜์ง€ ์•Š๋Š” Props๋Š” ์ „๋‹ฌ ๋ถˆ๊ฐ€

 

๐Ÿ‘‰  ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์—์„œ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋ฅผ import ํ•  ์ˆ˜ ์—†์Œ

  • ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์—์„œ ์„œ๋ฒ„์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ ๊ฒฝ์šฐ Next.js ์—์„œ๋Š” ์ž๋™์œผ๋กœ ์„œ๋ฒ„์ปดํฌ๋„ŒํŠธ๋ฅผ ํด๋ผ์ด์–ธํŠธ์ปดํฌ๋„ŒํŠธ๋กœ ๋ณ€๊ฒฝํ•จ

ํด๋ผ์ด์–ธํŠธ์ปดํฌ๋„ŒํŠธ ์•ˆ์— ์„œ๋ฒ„์ปดํฌ๋„ŒํŠธ๋ฅผ ๋„ฃ์„ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•!!!!

  • ์ง์ ‘ import ํ•ด์„œ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ธฐ
  • Children ์œผ๋กœ ๋„˜๊ฒจ์ค„ ๊ฒฝ์šฐ Next๋Š” ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋ฅผ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋กœ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š์Œ
  • ์„œ๋ฒ„์ปดํฌ๋„ŒํŠธ ๊ฒฐ๊ณผ๋ฌผ๋งŒ Props๋กœ ๋„˜๊ฒจ์ฃผ๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ํด๋ผ์ด์–ธํŠธ์—์„œ๋Š” ์„œ๋ฒ„์ปดํฌ๋„ŒํŠธ๋ฅผ ์‹คํ–‰ํ•˜์ง€ ์•Š์•„๋„ ๋จ

 

 

๐Ÿ‘‰ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ์—์„œ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์—๊ฒŒ ์ง๋ ฌํ™” ๋˜์ง€ ์•Š๋Š” Props๋Š” ์ „๋‹ฌ ๋ถˆ๊ฐ€

  • ํ•จ์ˆ˜๋Š” ์ง๋ ฌํ™”๊ฐ€ ๋ถˆ๊ฐ€๋Šฅ ํ•จ! ํ•จ์ˆ˜๋ฅผ props๋กœ ๋ณด๋‚ผ ์ˆ˜ ์—†์Œ

 

๐Ÿ‘‰ ์‚ฌ์ „ ๋ Œ๋”๋ง ๊ณผ์ • ์ง„ํ–‰

  • RSC Payload(์ง๋ ฌํ™”)์—๋Š” ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ์˜ ๋ชจ๋“  ๋ฐ์ดํ„ฐ๊ฐ€  ํฌํ•จ๋œ๋‹ค
    • ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ์˜ ๋ Œ๋”๋ง ๊ฒฐ๊ณผ
    • ์—ฐ๊ฒฐ๋œ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์˜ ์œ„์น˜ (ํ•จ์ˆ˜๋Š” ์ง๋ ฌํ™”๊ฐ€ ๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ „๋‹ฌ ๋ถˆ๊ฐ€๋Šฅ)
    • ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์—๊ฒŒ ์ „๋‹ฌํ•˜๋Š” Props ๊ฐ’

 

๐Ÿ‘‰  Navigation

... ๊ฐ•์˜๋“ฃ๊ณ  ๋งˆ์ € ์ž‘์„ฑ์˜ˆ์ •

 

 

 

 

์ถœ์ฒ˜: 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

'front-end > Next.js' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Next.js] (2) - ์‚ฌ์ „ ๋ Œ๋”๋ง  (0) 2024.10.31
[Next.js] (1) - React.js ์ „์šฉ์˜ ์›น ๊ฐœ๋ฐœ 'Framework'  (0) 2024.10.31