๐ฏ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SSR ์์ ์ Router ์ฑ๊ธํค์ ์ ๊ทผํ ๋ Next.js page ์ปดํฌ๋ํธ ์์ | |
| import Router from 'next/router' | |
| export default function page() { | |
| return ( | |
| <div> | |
| {/* ์๋ ์๋ฌ ๋ฐ์ | |
| * Error: No router instance found. | |
| * You should only use "next/router" on the client side of your app. | |
| * /} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SSR ์ฝ๋ | |
| // packages/next/server/render.tsx | |
| // renderToHTML์ ์ธํฐํ์ด์ค๋ ์๋ต. | |
| // https://github.com/vercel/next.js/blob/v12.3.4/packages/next/server/render.tsx#L351 | |
| export async function renderToHTML() { | |
| // CSR๊ณผ ๋ค๋ฅด๊ฒ SSR์์ ServerRouter๋ผ๋ ๋ณ๊ฐ์ class๋ก Router๋ฅผ ๋ง๋ ๋ค. | |
| // ServerRouter parameter๋ ์๋ต. | |
| const router = new ServerRouter() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // packages/next/client/index.ts | |
| // Router ์ฑ๊ธํค์ ์ ์ฅํ๋ ์ ์ญ ๊ฐ์ฒด | |
| // https://github.com/vercel/next.js/blob/v12.3.4/packages/next/client/index.tsx#L67 | |
| export let router: Router | |
| // AppContainer์์ RouterContext์ Router ์ฑ๊ธํค ์ฃผ์ ํ๋ ์ฝ๋ | |
| // https://github.com/vercel/next.js/blob/v12.3.4/packages/next/client/index.tsx#L296 | |
| function AppContainer({ | |
| children, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // packages/next/client/router.ts | |
| // import Router from 'next/router' ํ์ ๋ ์ ๊ทผํ๋ ๊ฐ. | |
| // Export the singletonRouter and this is the public API. | |
| export default singletonRouter as SingletonRouter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // packages/next/client/router.ts | |
| // Router ์ฑ๊ธํค์ ์ ์ฅํ๋ ๊ฐ์ฒด | |
| // https://github.com/vercel/next.js/blob/v12.3.4/packages/next/client/router.ts#L20 | |
| const singletonRouter: SingletonRouterBase = { | |
| router: null, // holds the actual router instance | |
| readyCallbacks: [], | |
| ready(cb: () => void) { | |
| if (this.router) return cb() | |
| if (typeof window !== 'undefined') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // packages/next/client/index.ts | |
| // Router ์ฑ๊ธํค์ ์ ์ฅํ๋ ์ ์ญ ๊ฐ์ฒด | |
| // https://github.com/vercel/next.js/blob/v12.3.4/packages/next/client/index.tsx#L67 | |
| export let router: Router | |
| // hydrate ํจ์์์ Router ์ฑ๊ธํค์ด ์ด๊ธฐํ(createRouter)๋๋ ์ฝ๋ ํธ์ถ | |
| // https://github.com/vercel/next.js/blob/v12.3.4/packages/next/client/index.tsx#L863 | |
| export async function hydrate(opts?: { beforeRender?: () => Promise<void> }) { | |
| // ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // packages/next/client/with-router.tsx | |
| // withRouter ์ฝ๋ | |
| // https://github.com/vercel/next.js/blob/v12.3.4/packages/next/client/with-router.tsx#L19 | |
| import { useRouter } from './router' | |
| export default function withRouter< | |
| P extends WithRouterProps, | |
| C extends BaseContext = NextPageContext | |
| >( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // packages/next/client/router.ts | |
| // useRouter ์ฝ๋ | |
| // https://github.com/vercel/next.js/blob/v12.3.4/packages/next/client/router.ts#L132 | |
| export function useRouter(): NextRouter { | |
| return React.useContext(RouterContext) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // packages/next/client/index.tsx | |
| // https://github.com/vercel/next.js/blob/v12.3.4/packages/next/client/index.tsx | |
| // ์ต์ด hydration์ ์ํด์ ์ฌ์ฉ | |
| // ๋ด๋ถ์์ render ํจ์ ํธ์ถ | |
| // ํจ์ ๋ด๋ถ๋ ์๋ต | |
| // https://github.com/vercel/next.js/blob/v12.3.4/packages/next/client/index.tsx#L756 | |
| export async function hydrate(opts?: { beforeRender?: () => Promise<void> }) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // packages/next/client/next.js | |
| // https://github.com/vercel/next.js/blob/v12.3.4/packages/next/client/next.js#L12 | |
| // Next.js client side initialize ์ฝ๋ | |
| initialize({}) | |
| .then(() => hydrate()) | |
| .catch(console.error) |
NewerOlder