Data sharing (Solving props drilling)
next.js 13.4 ์ด์ App router ๊ธฐ์ค์ผ๋ก ์์ฑํ์์ต๋๋ค.
props drilling ์์
next.js์์ ์ฃผ๋ก ๋ฐ์ํ๋ props drilling ํํ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
- ๋จผ์ ํ์ํ ๋ฐ์ดํฐ๋ฅผ ์๋ฒ์ปดํฌ๋ํธ์์ fetch ํฉ๋๋ค. API ๋ ธ์ถ ๋ฐฉ์ง, ์ต์ ํ ๋ฑ ๋ค์ํ ์ด์ ๋ก ์๋ฒ ์ปดํฌ๋ํธ(์๋ฒ ์ฌ์ด๋)์์ API๋ฅผ ํธ์ถํฉ๋๋ค.
// Server Component A
import ServerComponentB from "./ServerComponentB"
export default async function ServerComponentA() {
const initialCount = await fetch(...);
return <>
<h3>I got {initialCount}</h3>
<ServerComponentB initialCount={initialCount} />
</>
}- ๋ฐ์ดํฐ๋ฅผ fetchํ ์๋ฒ์ปดํฌ๋ํธ์์ ํ์ ์๋ฒ์ปดํฌ๋ํธ๋ก ๋ฐ์ดํฐ๋ฅผ ๋๊ฒจ์ค๋๋ค.
ServerComponentB์์๋ initialCount๊ฐ ํ์์์ง๋ง, ํ์ ์ปดํฌ๋ํธ์์ ํ์ํ๊ธฐ์ ๋ฐ๊ณ , ๋๊ฒจ์ค๋๋ค.
// Server Component B
import ServerComponentC from "./ServerComponentC"
export default function ServerComponentB({ initialCount }) {
return <ServerComponentC initialCount={initialCount}/>
}ServerComponentC์์๋initialCount๊ฐ ํ์ํฉ๋๋ค. ํ์ํ ์์ ์ ์ํ ํ ํ์ ์ปดํฌ๋ํธ๋ฅผ ๋ถ๋ฌ์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ๊ทธ ํ์ ์ปดํฌ๋ํธ์๋initialCount๊ฐ ํ์ํ๊ธฐ์ props๋ก ๋ฐ์ ๋ฐ์ดํฐ๋ฅผ ๋๊ฒจ์ค๋๋ค.
// Server Component C
import ClientComponent from "./ClientComponent"
export default function ServerComponentC({ initialCount }) {
return (
<div>
<h3>initial count is : {initialCount}</h3>
<ClientComponent initialCount={initialCount}/>
</div>
)
}- ์ต์ข ์ ์ผ๋ก ์ตํ์ ์ปดํฌ๋ํธ์ ๋๋ฌํ์์ต๋๋ค.
// Client Component
'use client'
import {useState} from "react"
export default function ClientComponent({initialCount}) {
const [count, setCount] = useState(initialCount);
return (
<>
{count}
<button onClick={() => setCount(prev => prev + 1)}>+1</button>
<button onClick={() => setCount(prev => prev - 1)}>-1</button>
</>
)
}์ด์ฒ๋ผ ์์ ์ปดํฌ๋ํธ์ ์๋ ๋ฐ์ดํฐ๋ฅผ ํ์ ์ปดํฌ๋ํธ์์๋ ๊ฐ์ ธ์ผํ๊ณ ์ด๊ฒ์ props๋ก ๋๊ฒจ์ค๋, props drilling์ด ๋ฐ์ํฉ๋๋ค. ์ค๊ฐ์ ServerComponentB์์๋ initialCount๊ฐ ํ์์์์ง๋ง ํ์ ์ปดํฌ๋ํธ์์ ํ์ํ๊ธฐ์ ๋ฐ๊ณ ๋๊ฒจ์ค์ผํ์ต๋๋ค.
๋ง์ฝ ์ผ๋ฐ์ ์ธ React ์ฑ์ฒ๋ผ ํด๋ผ์ด์ธํธ ์ปดํฌ๋ํธ๋ก๋ง ๊ตฌ์ฑ๋์ด์๋ค๋ฉด ๊ธ๋ก๋ฒ ์ํ๊ด๋ฆฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ(redux, recoil..)๋, Context API๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค. ํ์ง๋ง ์๋ฒ์ปดํฌ๋ํธ์์๋ ์ํ๋ฅผ ์ฌ์ฉํ ์ ์๊ธฐ์ ์์ ๊ฐ์ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๊ธฐ ์ด๋ ต์ต๋๋ค.
์ฌ๊ธฐ์๋ ์๋ฒ์ปดํฌ๋ํธ๊ฐ ์๋ ๊ตฌ์กฐ์์ props drilling ๋ฌธ์ ์์ด ๋ฐ์ดํฐ๋ฅผ ๊ณต์ ํ ์ ์๋ ๋ฐฉ๋ฒ์ ์์ฑํ์์ต๋๋ค.
Server Component โ Server Component
next.js์์ ๊ธฐ๋ณธ์ผ๋ก ์ ๊ณตํด์ฃผ๋ ๊ธฐ๋ฅ์ธ Automatic fetch() Requst Deduping์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
next.js ๊ณต์๋ฌธ์์์์ ์ค๋ช
์ ๋ฐ๋ฅด๋ฉด, ์๋ฒ์์ fetch๋ก GETํ ๋ฐ์ดํฐ๋ rendering pass ๋์ ์บ์๋๋ค๊ณ ํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ด ์บ์๋ server request ์๋ช
์ฃผ๊ธฐ๋์ ์ ์ง๋๋ฉฐ ๋ ๋๋ง ๊ณผ์ ์ด ๋๋ ๋๊น์ง ์ง์๋๋ค๊ณ ํฉ๋๋ค.
๋ฐ๋ผ์ ์๋ฒ์ปดํฌ๋ํธ๋ผ๋ฆฌ๋ ๋ณ๋์ data sharing ๊ธฐ๋ฒ์ด ํ์ํ์ง ์๊ณ , ๋งค๋ฒ ํ์ํ ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์ค๋ฉด ๋ฉ๋๋ค.
// Server Component A
import ServerComponentB from "./ServerComponentB"
export default async function ServerComponentA() {
const initialCount = await fetch(...);
return <>
<h3>I got {initialCount}</h3>
<ServerComponentB/>
</>
}// Server Component B
import ServerComponentC from "./ServerComponentC"
export default function ServerComponentB() {
return <ServerComponentC/>
}// Server Component C
import ClientComponent from "./ClientComponent"
export default function ServerComponentC() {
const initialCount = await fetch(...);
return (
<div>
<h3>initial count is : {initialCount}</h3>
<ClientComponent initialCount={initialCount}/>
</div>
)
}์ด์ ServerComponentB์์๋ initialCount๋ฅผ ๋ฐ์ ํ์๋, ๋๊ฒจ์ค ํ์๋ ์์ต๋๋ค. fetch() ๋์ ๊ฒฐ๊ณผ๊ฐ ์บ์๋์ด์๊ธฐ ๋๋ฌธ์ ๋๋ฒ์ด์ API ์์ฒญ์ ๋ณด๋ด์ง ์์ต๋๋ค.
ํ๊ณ์
์ ๋ ๊ฐ๋ฐ์ ํ๋ฉด์ ์๋ฒ์ปดํฌ๋ํธ์์ API ์์ฒญ์ ๋ณด๋ผ๋ ์ฃผ๋ก searchParams์ ๋ค์ด์จ ๊ฐ์ ๊ธฐ์ค์ผ๋ก API๋ฅผ ํธ์ถํ์ต๋๋ค.
// ex : ํด๋ผ์ด์ธํธ ์์ฒญ ์ฃผ์ -> /notice?categoryId=4&searchValue=test
// categoryId=4, searchValue=test ๋ก ๋ฐ์ดํฐ๋ฅผ ๋ฐ์์ด
export default async function NoticePage({ searchParams : {categoryId, searchValue } }) {
const notices = await getNotices({ categoryId, searchValue })
...
}ํ์ง๋ง next.js app router์์ page.js๊ฐ ์๋ ์๋ฒ์ปดํฌ๋ํธ์์ searchParams๋ฅผ ์ป์ด์ฌ ์ ์๋ ๊ณต์์ ์ผ๋ก ์ ๊ณตํ๋ ๋ฐฉ๋ฒ์ ์์ต๋๋ค. ๋ฐ๋ผ์ ์์์ ์ค๋ช
ํ, ๋ฐ์ดํฐ๊ฐ ํ์ํ ์๋ฒ์ปดํฌ๋ํธ์์ api๋ฅผ ์์ฒญํ๋ ๊ฑด ์ด๋ ต์ต๋๋ค. API ์์ฒญ์ ํ์ํ searchParams๋ฅผ ์ป์ ์ ์๊ธฐ ๋๋ฌธ์
๋๋ค.
// page.js๊ฐ ์๋ ์ด๋๊ฐ์ ์๋ฒ์ปดํฌ๋ํธ
export default function NoticeList() {
// error! categoryId, searvhValue๋ฅผ ์์๋ผ ์ ์์
const notices = await getNotices({ categoryId, searchValue })
}๋ฐ๋ผ์ Server Component -> Server Component data sharing์ ์ข ๋ ์ ํ์ฉํ๋ ค๋ฉด, ํ๋์ Request๊ฐ ์ด์์๋ ๋์ ์ฌ๋ฌ ์๋ฒ์ปดํฌ๋ํธ์์ ๊ทธ Request์ searchParams์ ์ ๊ทผ๊ฐ๋ฅํด์ผํฉ๋๋ค.
๊ณต์์ ์ธ ๋ฐฉ๋ฒ์ ์๋๋ ๋ช๊ฐ์ง ์๊ฐํด๋ณธ/์ฐพ์๋ณธ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
-
์น์๋ฒ ํ์ฉ
next.js์์๋ ์๋ฒ์ปดํฌ๋ํธ์ headers()๋ผ๋ ํจ์๋ฅผ ์ ๊ณตํฉ๋๋ค. ์์ฒญ์ด ์จ Request์ header์ ์ ๊ณตํด์ฃผ๋ ํจ์์ ๋๋ค. ์ด ํจ์๋ ๊ผญ
page.js๋ง์ด ์๋ ๊ณณ์์๋ ์ฌ์ฉ๊ฐ๋ฅํ๊ธฐ์, header์ searchParams๊ฐ ๋ค์ด์๋ค๋ฉดpage.js๊ฐ ์๋ ์๋ฒ์ปดํฌ๋ํธ์์๋ searchParams์ ์ ๊ทผ ๊ฐ๋ฅํฉ๋๋ค.# nginx ์์ server { location / { proxy_set_header X-Search-Params $args; proxy_pass http://localhost:3000; } }import { headers } from 'next/headers' export default function NoticeList() { const header = headers() const { categoryId, searchValue } = parseSearchParams(header.get("X-Search-Params")) const notices = await getNotices({ categoryId, searchValue }) } -
searchParams ์ ๋๋ props๋ก ๋ด๋ ค๋ณด๋ด๊ธฐ
page.js์์ searchParams๊ฐ ํ์ํ ์๋ฒ์ปดํฌ๋ํธ๊น์ง ๋ด๋ ค์ค์ผํ์ง๋ง,searchParams๊ฐ์ฒด ํ๋๋ง ๋ด๋ ค์ฃผ๋ฉด ๋๊ธฐ์ props drilling์ ํ๋์ ๊ฐ์ฒด๋ง ๋ด๋ ค๋ณด๋ด๋ ์์ค์ผ๋ก ์ ์งํ ์ ์์ต๋๋ค.export default function NoticeList({searchParams : {categoryId, searchValue }}) { const notices = await getNotices({ categoryId, searchValue }) }๊ด๋ จํด์ next.js ๊นํ๋ธ discussions์์ ๋ ผ์๋ ์๊ธฐ๊ฐ ์๋๋ฐ, searchParams์ ๋ํ validation/parsing/error handling ์์ด ํ์ ์ปดํฌ๋ํธ๋ก searchParams๋ฅผ ๋๊ฒจ์ค ๊ฐ๋ฅ์ฑ์ ์ ๋ค๋ ๋๊ธ์ด ์์์ต๋๋ค. ๊ฐ๋ฅ์ฑ์ด ์ ์์ง๋ ๋ชจ๋ฅด๊ฒ ์ผ๋, ํ์คํ ํ์ฑ, ์ ํจ์ฑ ๊ฒ์ฆ์ด ํ์ํ searchParams์ ๊ฒฝ์ฐ
page.js์์ ๋จผ์ ๋ฐ์ ์ฒ๋ฆฌ๋ฅผ ํ ํ, ํ์ ์ปดํฌ๋ํธ๋ก props๋ก ๋๊ฒจ์ฃผ๋๊ฒ ๋ ์ข์ ๋ฐฉ๋ฒ์ผ๋ก ๋ณด์ ๋๋ค. -
์๋ฒ๋จ์์ data sharing ํด ์ฌ์ฉ
๊ผญ searchParams์ ๊ตญํ๋์ง ์๋๋ผ๋, ์๋ฒ์ปดํฌ๋ํธ๋ค ์ฌ์ด์์ ๋ฐ์ดํฐ or context๋ฅผ ๊ณต์ ํ๋ฉด ์ข์ ๊ฒฝ์ฐ๊ฐ ๋ง์ต๋๋ค. (i18n, theme ๋ฑ). next.js discussions
๊ณต์์ ์ผ๋ก ์ ๊ณตํด์ฃผ๋ ๋ฐฉ๋ฒ์ ์์ง๋ง, ์๋ํํฐ ํด์ ๋ง๋๋ ค๋ ์๋๋ ์กด์ฌํฉ๋๋ค(server-only-context, react cache function ํ์ฉ). ๊ณต์๋ฌธ์์์๋ db์ ๊ฐ์ด ๋ค์ดํฐ๋ธ JS ํจํด์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์ถ์ฒํด์ฃผ๊ณ ์์ต๋๋ค. ๋งํฌ
Client Component โ Client Component
์์ฃผ ์๋ ์ํฉ์ผ๋ก, ์ด๋ค ํด๋ผ์ด์ธํธ ์ปดํฌ๋ํธ์ ๋๋ ํฐ๋ฆฌ ์ ๋จผ ๊ณณ์ ์๋ ํด๋ผ์ด์ธํธ ์ปดํฌ๋ํธ๊ฐ ๋ฐ์ดํฐ ๋๋ ์ํ๋ฅผ ๊ณต์ ํด์ผํ๋ ๊ฒฝ์ฐ๊ฐ ์์ ์ ์์ต๋๋ค. ์ด๋ด๋๋ ์ผ๋ฐ์ ์ผ๋ก ๋ฆฌ์กํธ ์ฑ์ ๊ฐ๋ฐํ ๋ ์ฌ์ฉํ๋ ์ ์ญ ์ํ ๊ด๋ฆฌ ๋ฐฉ๋ฒ์ ์ฑํํ ์ ์์ต๋๋ค. next.js ๊ณต์๋ฌธ์์์๋ Context API ๋ฐ ์๋ํํฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ํ ์ค๋ช ์ ์์ต๋๋ค. ๋งํฌ
์์๋ก๋ Context API๋ฅผ ์ฌ์ฉํ์์ต๋๋ค.
// layout.tsx
import { AppProvider } from '../lib/AppProvider';
export default function RootLayout({ children }) {
return (
<html lang="en">
<body className={inter.className}>
<AppProvider>{children}</AppProvider>
</body>
</html>
);
}// lib/AppProvider.tsx
'use client';
import React, { createContext, useState, useContext } from 'react';
const AppContext = createContext();
export const AppProvider = ({ children }) => {
const [state, setState] = useState(0);
const value = {
state,
setState,
};
return <AppContext.Provider value={value}>{children}</AppContext.Provider>;
}
export const useAppContext = () => useContext(AppContext);// page.tsx
import Counter from '../components/counter';
import ServerComp from '../components/server';
export default function Home() {
return (
<main className={styles.main}>
<ServerComp />
<Counter />
</main>
);
}// components/counter.tsx
'use client';
import { useAppContext } from '../lib/AppProvider';
export default function Counter() {
const { state, setState } = useAppContext();
const increaseHandler = () => {
setState(state + 1);
};
const decreaseHandler = () => {
setState(state - 1);
};
// Use the state and setState as needed
return (
<>
<div>{state}</div>
<a href="#" onClick={increaseHandler}>
increase
</a>{' '}
<a href="#" onClick={decreaseHandler}>
decrease
</a>
</>
);
}- ์คํด : Context Provider๋ ํด๋ผ์ด์ธํธ ์ปดํฌ๋ํธ์ด๊ณ , ์ด๊ฒ์ ๊ฐ์ฅ ์์์ ๋๋ฉด ๊ทธ ์๋๋ ์ ๋ถ ํด๋ผ์ด์ธํธ ๋ฒ๋ค์ ํฌํจ๋ ๊ฑฐ๋ผ๊ณ ์คํดํ๋ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค. ๊ทธ ์ด์ ๋ next.js ๊ณต์๋ฌธ์์ ์๋์ ๊ฐ์ ๋ฌธ๊ตฌ๊ฐ ์๊ธฐ ๋๋ฌธ์ธ๋ฐ์.
Once
"use client"is defined in a file, all other modules imported into it, including child components, are considered part of the client bundlehttps://nextjs.org/docs/getting-started/react-essentials#the-use-client-directive
ํด๋ผ์ด์ธํธ ์ปดํฌ๋ํธ์ ์์ ์ปดํฌ๋ํธ๋ค์ ํด๋ผ์ด์ธํธ ๋ฒ๋ค๋ก ๊ฐ์ฃผ๋๋ค๋ ๋ด์ฉ์ ๋๋ค. ๋ฐ๋ผ์ Context API Provider๋ฅผ ์์์ ๋๋ฉด ๊ทธ ํ์ ์๋ฒ์ปดํฌ๋ํธ๋ค๋ ๋ชจ๋ ํด๋ผ์ด์ธํธ ๋ฒ๋ค์ ํฌํจ๋์ด ์๋ฒ์ปดํฌ๋ํธ๋ฅผ ์ฌ์ฉํ๋ ์ด์ ๊ฐ ์์ด์ง๊ฒ๋ง ๊ฐ์ต๋๋ค.
ํ์ง๋ง ์คํํด๋ณธ ๊ฒฐ๊ณผ, ํด๋ผ์ด์ธํธ ๋ฒ๋ค์ ํฌํจ๋์ง ์์์ต๋๋ค. ์ด์ ๋ ServerComponent๊ฐ ClientComponent(Context Provider)์ ์ง์ import ๋์ง ์๊ณ , props๋ก ๋์ด๊ฐ๊ธฐ ๋๋ฌธ์ ๋๋ค
next.js ๊ณต์ ๋ฌธ์์ ๋ฐ๋ฅด๋ฉด ์๋ฒ์ปดํฌ๋ํธ๋ฅผ ํด๋ผ์ด์ธํธ ์ปดํฌ๋ํธ ๋ฐ์ ๋๋ ค๋ฉด, import ํ์ง ๋ง๊ณ prop(children)์ผ๋ก ๋๊ฒจ์ค์ผํ๋ค๊ณ ๋์ด์์ต๋๋ค. ๋งํฌ
// Unsupported Pattern: Importing Server Components into Client Components
'use client'
// This pattern will **not** work!
// You cannot import a Server Component into a Client Component.
import ExampleServerComponent from './example-server-component'
export default function ExampleClientComponent({
children,
}: {
children: React.ReactNode
}) {
const [count, setCount] = useState(0)
return (
<>
<button onClick={() => setCount(count + 1)}>{count}</button>
<ExampleServerComponent />
</>
)
}// Recommended Pattern: Passing Server Components to Client Components as Props
'use client'
import { useState } from 'react'
export default function ExampleClientComponent({
children,
}: {
children: React.ReactNode
}) {
const [count, setCount] = useState(0)
return (
<>
<button onClick={() => setCount(count + 1)}>{count}</button>
{children}
</>
)
}๊ณต์ ๋ฌธ์์ ์ค๋ช ๋์ด ์๋๋๋ก, import ๋์ props(children)์ผ๋ก ๋๊ฒจ์ฃผ๋ฉด ํด๋ผ์ด์ธํธ ์ปดํฌ๋ํธ๋ ์์ ์ปดํฌ๋ํธ๋ฅผ ์ํ slot์ ๋จ๊ธฐ๊ณ , ์๋ฒ์ปดํฌ๋ํธ ๋ ๋๊ฐ ์ข ๋ฃ๋๋ฉด ๊ทธ slot์ ์๋ฒ ์ปดํฌ๋ํธ๊ฐ ๋ ๋๋ง ๋ฉ๋๋ค. ์ด ๋ฐฉ์๋๋ก ํ๋ค๋ฉด ์๋ฒ์ปดํฌ๋ํธ๋ ํด๋ผ์ด์ธํธ ๋ฒ๋ค์ ํฌํจ๋์ง ์๊ณ , ์๋ฒ์ปดํฌ๋ํธ๋ก์จ ๋์ํฉ๋๋ค.
Server Component โ Client Component
โServer Component โ Server Componentโ์์ ํ๋ ๊ฒ์ฒ๋ผ, ํ๋ฒ ๋ถ๋ฅธ fetch์ ๊ฒฐ๊ณผ๋ ๊ฐ์ ์์ฒญ์ด ์ด์์๋ ๋์ ์บ์๋๋ค๋ ๊ฒ์ ํ์ฉํ ์ ์์ต๋๋ค. ๋ฐ์ดํฐ๊ฐ ํ์ํ ํด๋ผ์ด์ธํธ ์ปดํฌ๋ํธ๋ฅผ ์๋ฒ์ปดํฌ๋ํธ๋ก ํ๋ฒ ๊ฐ์ธ์ props drilling์ ์ํํ ์ ์์ต๋๋ค. ๊ด๋ จ ๋งํฌ(์ ํ๋ธ ์์, ์๋ฆฌ์ฃผ์)
// Server Component A
import ServerComponentB from "./ServerComponentB"
export default async function ServerComponentA() {
const initialCount = await fetch(...);
return <>
<h3>I got {initialCount}</h3>
<ServerComponentB />
</>
}// Server Component B
import ServerComponentC from "./ServerComponentC"
export default function ServerComponentB() {
return <ServerComponentC/>
}// Server Component C
import ClientComponent from "./ClientComponent"
export default function ServerComponentC() {
const initialCount = await fetch(...);
return <ClientComponent initialCount={initialCount}/>
}// Client Component
'use client'
import {useState} from "react"
export default function ClientComponent({initialCount}) {
const [count, setCount] = useState(initialCount);
return (
<>
{count}
<button onClick={() => setCount(prev => prev + 1)}>+1</button>
<button onClick={() => setCount(prev => prev - 1)}>-1</button>
</>
)
}Client Component โ Server Component
props๋ก ๋๊ฒจ์ฃผ๋ ๋ฐฉ๋ฒ์ด๋, ๋ค์๊ณผ ๊ฐ์ด cloneElement๋ฅผ ์ด์ฉํ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค.
import React from "react";
import ClientComponent from "./ClientComponent"
export default function ParentComponent({ children }) {
return (
<ClientComponent>
<ServerComponent/>
</ClientComponent>
)
}'use client'
import React from "react";
export default function ClientComponent({ children }) {
return (
<div>
{React.cloneElement(children, {name:"test props"})}
</div>
)
}import React from "react";
export default function ServerComponent({ name }) {
return (
<div>
{name}
</div>
)
}ํ์ง๋ง ๊ฐ๋ฅํ ๊ฒ๊ณผ๋ ๋ณ๊ฐ๋ก ํฌ๊ฒ ํจ์ฉ์ฑ์ด ์์์ง๋ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ์ด ๋ฐฉ๋ฒ์ ํด๋ผ์ด์ธํธ ์ปดํฌ๋ํธ์ ๋ฐ๋ก ํ๋จ๊ณ ๋ฐ ์๋ฒ์ปดํฌ๋ํธ๋ก๋ง ์ ๋ฌ์ด ๊ฐ๋ฅํ๊ธฐ์, ํด๋ผ์ด์ธํธ ์ปดํฌ๋ํธ์์ ์๋ฒ์ปดํฌ๋ํธ๋ฅผ ๋ณ๊ฒฝํ๋ ค๋ฉด URL ์ฟผ๋ฆฌ๋ฅผ ๋ณ๊ฒฝํ์ฌ ์๋ก ํ์ด์ง๋ฅผ fetchํ๋๊ฒ ๋์ ์๋ ์์ต๋๋ค. URL ์ฟผ๋ฆฌ๋ฅผ ๋ณ๊ฒฝํ๋ ๊ฒฝ์ฐ ํ๋จ๊ณ ๋ฐ ์๋ฒ์ปดํฌ๋ํธ๋ฟ๋ง ์๋๋ผ ๊ด๋ จ์๋ ๋ชจ๋ ์๋ฒ์ปดํฌ๋ํธ๋ค๋ ๋ณ๊ฒฝ์ด ๊ฐ๋ฅํ๊ธฐ ๋๋ฌธ์ ๋๋ค.