๋ด๋ณด๋ด๋ฒ(๋ด๊ฐ ๋ณด๋ ค๊ณ ๋ด๊ฐ ๋ฒ์ญํ...) Next.js docs
2021๋ 3์ 30์ผ ๊ธฐ์ค Next.js ๊ณต์ ๋ฌธ์๋ฅผ ๋ฒ์ญํ๋ค.
โป ์์ด ์ ๊ณต์๋ ํด์ธ ์ ํํ๋ ์๋๊ธฐ์ ๋ฒ์ญ์๋ ์์ญ, ์ค์ญ, ๊ตฌ๊ธ ๋ฒ์ญ์ด ๋ฌด์ํ ๋ง์ ์ ์์ผ๋ฉฐ, ํผ์ ๊ณต์๋ฌธ์๋ฅผ ์ฐธ์กฐํด๊ฐ๋ฉฐ ๋ฒ์ญํ๋ค ๋ณด๋ ์คํ๋ ๋ง์ ์ ์๋ค. ์ ํํ ๋ด์ฉ์ ๊ณต์๋ฌธ์๋ฅผ ์ง์ ์ดํด๋ณด๊ฑฐ๋ ๋ค๋ฅธ ์ ๋ณด๋ค์ ๋ ์ฐพ์๋ณด๋ ๊ฒ์ ์ถ์ฒํ๋ค.
(ํ์ง๋ง ๋๊ธ ํผ๋๋ฐฑ๋ ํ์ํฉ๋๋ค๐ )
Next.js ๊ณต์๋ฌธ์ ํ์ธํ๊ธฐ>>
Introduction
Next.js has a file-system based router built on the concept of pages.
When a file is added to the pages directory it's automatically available as a route.
The files inside the pages directory can be used to define most common patterns.
Next.js์๋ ํ์ด์ง ๊ฐ๋ ์ ๊ธฐ๋ฐ์ผ๋ก ๊ตฌ์ถ ๋ ํ์ผ ์์คํ ๊ธฐ๋ฐ ๋ผ์ฐํฐ๊ฐ ์๋ค.
ํ์ผ์ด pages ๋๋ ํฐ๋ฆฌ์ ์ถ๊ฐ๋๋ฉด ์๋์ผ๋ก ๊ฒฝ๋ก ์ ๊ทผ์ด ๊ฐ๋ฅํด์ง๋ค.
ํ์ผ ๋๋ ํฐ๋ฆฌ ๋ด๋ถ์ ํ์ผ๋ค์ ์ฌ์ฉํ์ฌ ๊ฐ์ฅ ์ผ๋ฐ์ ์ธ ํจํด์ ์ ์ํ ์ ์๋ค.
Index routes
The router will automatically route files named index to the root of the directory.
๋ผ์ฐํฐ๋ index๋ผ๋ ํ์ผ์ ๋๋ ํฐ๋ฆฌ์ ๋ฃจํธ๋ก ์๋ ๋ผ์ฐํ
ํด์ค๋ค.
- pages/index.js → /
- pages/blog/index.js → /blog
Nested routes
The router supports nested files. If you create a nested folder structure files will be automatically routed in the same way still. ๋ผ์ฐํฐ๋ ์ค์ฒฉ๋ ํ์ผ๋ค์ ๋ํด์๋ ์ง์ํ๋ค. ์ค์ฒฉ๋ ํด๋ ๊ตฌ์กฐ๋ฅผ ๋ง๋ค์ด๋ ํ์ผ๋ค์ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ์๋ ๋ผ์ฐํ ๋ ๊ฒ์ด๋ค.
- pages/blog/first-post.js → /blog/first-post
- pages/dashboard/settings/username.js → /dashboard/settings/username
Dynamic route segments
To match a dynamic segment you can use the bracket syntax. This allows you to match named parameters.
๋์ ์ธ ์ธ๊ทธ๋จผํธ๋ฅผ ์ผ์น์ํค๊ธฐ ์ํด์ ๋๊ดํธ ๊ตฌ๋ฌธ์ ์ฌ์ฉํ ์ ์๋ค. ์ด๋ ๊ฒ ํ๋ฉด ๋ช
๋ช
๋ ํ๋ผ๋ฏธํฐ๋ค๊ณผ ์ผ์น์ํฌ ์ ์๋ค.
- pages/blog/[slug].js → /blog/:slug (/blog/hello-world)
- pages/[username]/settings.js → /:username/settings (/foo/settings)
- pages/post/[...all].js → /post/* (/post/2020/id/title)
Check out the Dynamic Routes documentation to learn more about how they work.
์ด๋ป๊ฒ ๋์ํ๋์ง ํ์ธํ๋ ค๋ฉด Dynamic Routes ๋ฌธ์๋ฅผ ํ์ธํ๋ผ.
Linking between pages
The Next.js router allows you to do client-side route transitions between pages, similar to a single-page application.
A React component called Link is provided to do this client-side route transition.
Next.js ๋ผ์ฐํฐ๋ ํ์ด์ง ๊ฐ์ ํด๋ผ์ด์ธํธ ์ธก ๊ฒฝ๋ก ์ ํ์ด ๊ฐ๋ฅํ๊ฒ ํด์ค๋ค. ์ฑ๊ธ ํ์ด์ง ์ดํ๋ฆฌ์ผ์ด์ ๊ณผ ๋น์ทํ๋ค.
Link๋ผ๋ ๋ฆฌ์กํธ ์ปดํฌ๋ํธ๋ ์ด๋ฌํ ํด๋ผ์ด์ธํธ ์ธก ๊ฒฝ๋ก ์ ํ์ ์ ๊ณตํด์ค๋ค.
In the example above we have multiple links, each one maps a path (href) to a known page:
์์ ์์ ์์ ๋ค์์ ๋งํฌ๋ค์ด ์๊ณ ๊ฐ ๋งํฌ๋ ์๋ ค์ ธ ์๋ ํ์ด์ง๋ก ๋งคํ๋์ด์๋ค.
- / → pages/index.js
- /about → pages/about.js
- /blog/hello-world → pages/blog/[slug].js
Any <Link /> in the viewport (initially or through scroll) will be prefetched by default (including the corresponding data) for pages using Static Generation. The corresponding data for server-rendered routes is not prefetched.
๋ทฐํฌํธ(์ด๊ธฐ์ด๊ฑฐ๋ ์คํฌ๋กค์ ํตํด์ ์ด๊ฑฐ๋) ๋ด๋ถ์ ์๋ ์ด๋ ํ <Link />์ด๋ ์ ์ ์์ฑ์ ์ฌ์ฉํ์ฌ ํ์ด์ง๋ฅผ ์ํด ๊ธฐ๋ณธ์ ์ผ๋ก (ํด๋นํ๋ ๋ฐ์ดํฐ๋ฅผ ํฌํจํ์ฌ) ๋จผ์ ํจ์น๋ ๊ฒ์ด๋ค. ์๋ฒ ๋ ๋๋ง ๊ฒฝ๋ก์ ํด๋นํ๋ ๋ฐ์ดํฐ๋ ๋จผ์ ํจ์น๋์ง ์๋๋ค.
Linking to dynamic paths
You can also use interpolation to create the path, which comes in handy for dynamic route segments. For example, to show a list of posts which have been passed to the component as a prop:
๊ฒฝ๋ก๋ฅผ ์์ฑํ๊ธฐ ์ํด์ interpolation(${link}์ด๋ฌํ ํํ)์ ์ฌ์ฉํ ์ ์๋๋ฐ ์ด๋ ๊ฒ ํ๋ ๊ฒ์ ๋์ ๊ฒฝ๋ก ์ธ๊ทธ๋จผํธ๋ค์ ์ ์ฉํ๋ค. ์๋ฅผ ๋ค์ด ์ปดํฌ๋ํธ์ prop์ผ๋ก ์ ๋ฌ๋์ด์ง ํฌ์คํธ ๋ฆฌ์คํธ๋ค์ ๋ณด์ฌ์ฃผ๋ ๊ฒ๊ณผ ๊ฐ์ ๊ฒฝ์ฐ.
encodeURIComponent is used in the example to keep the path utf-8 compatible.
์ด ์์ ์ ์ฌ์ฉ๋ encodeURIComponent๋ ๊ฒฝ๋ก๋ฅผ utf-8 ํธํ๊ฐ๋ฅํ๊ฒ ์ ์งํด์ค๋ค.
Alternatively, using a URL Object:
๊ทธ๋ ์ง ์์ผ๋ฉด URL ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ ์๋ ์๋ค.
Now, instead of using interpolation to create the path, we use a URL object in href where:
- pathname is the name of the page in the pages directory. /blog/[slug] in this case.
- query is an object with the dynamic segment. slug in this case.
๊ฒฝ๋ก๋ฅผ ๋ง๋ค๊ธฐ ์ํด์ interpolation์ ์ฌ์ฉํ๋ ๋์ href์ URL ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ์๋ค.
- pathname์ pages ๋๋ ํฐ๋ฆฌ์ ์๋ ํ์ด์ง์ ์ด๋ฆ์ด๋ค. ์ด ๊ฒฝ์ฐ์๋ /blog/[slug]์ด๋ค.
- query๋ ๋์ ์ธ๊ทธ๋จผํธ๊ฐ ์๋ ๊ฐ์ฒด์ด๋ค. ์ด ๊ฒฝ์ฐ์๋ slug์ด๋ค.
Injecting the router
To access the [router object](https://nextjs.org/docs/api-reference/next/router#router-object) in a React component you can use [useRouter](<https://nextjs.org/docs/api-reference/next/router#userouter>) or [withRouter](<https://nextjs.org/docs/api-reference/next/router#withrouter>).
In general we recommend using [useRouter](<https://nextjs.org/docs/api-reference/next/router#userouter>).
๋ฆฌ์กํธ ์ปดํฌ๋ํธ์ router ๊ฐ์ฒด์ ์ ๊ทผํ๊ธฐ ํ๋ ค๋ฉด useRouter ํน์ withRouter๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
๋ณดํต์ useRouter๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ์ถ์ฒํ๋ค.
Dynamic Routes
Defining routes by using predefined paths is not always enough for complex applications. In Next.js you can add brackets to a page ([param]) to create a dynamic route (a.k.a. url slugs, pretty urls, and others).
๋จผ์ ์ ์๋ ๊ฒฝ๋ก๋ง ์ฌ์ฉํด์ ๋ผ์ฐํธ๋ฅผ ์ ์ํ๋ ๊ฒ์ ๋ณต์กํ ์ดํ๋ฆฌ์ผ์ด์ ์๋ ํญ์ ์ถฉ๋ถํ ๊ฒ์ ์๋๋ค. Next.js์์๋ ๋์ ๋ผ์ฐํธ๋ฅผ ์์ฑํ๋ ค๋ฉด ํ์ด์ง์ ๋๊ดํธ๋ฅผ ๋ํด์ฃผ๋ฉด ๋๋ค.
Consider the following page pages/post/[pid].js:
์๋์ pages/post/[pid].js๋ผ๋ ํ์ด์ง๋ฅผ ์ดํด๋ณด์:
Any route like /post/1, /post/abc, etc. will be matched by pages/post/[pid].js. The matched path parameter will be sent as a query parameter to the page, and it will be merged with the other query parameters.
/post/1, /post/abc์ ๊ฐ์ ์ด๋ค ๋ผ์ฐํธ๋ก pages/post/[pid].js์ ๋งค์น๋ ๊ฒ์ด๋ค. ๋งค์น๋ ๊ฒฝ๋ก ํ๋ผ๋ฏธํฐ๋ ์ฟผ๋ฆฌ ํ๋ผ๋ฏธํฐ๋ก ํ์ด์ง์ ์ ์ก๋ ๊ฒ์ด๊ณ ๋ค๋ฅธ ์ฟผ๋ฆฌ ํ๋ผ๋ฏธํฐ์ ํจ๊ป ํฉ์ณ์ง ๊ฒ์ด๋ค.
For example, the route /post/abc will have the following query object:
์๋ฅผ ๋ค์ด /post/abc/ ๋ผ์ฐํธ๋ ์๋์ ๊ฐ์ ์ฟผ๋ฆฌ ๊ฐ์ฒด๋ฅผ ๊ฐ๋๋ค:
Similarly, the route /post/abc?foo=bar will have the following query object:
๋น์ทํ๊ฒ /post/abc?foo=bar ๋ผ์ฐํธ๋ ์๋์ ๊ฐ์ ์ฟผ๋ฆฌ ๊ฐ์ฒด๋ฅผ ๊ฐ๋๋ค:
However, route parameters will override query parameters with the same name. For example, the route /post/abc?pid=123 will have the following query object:
ํ์ง๋ง ๊ฐ์ ์ด๋ฆ์ ๊ฐ์ง ์ฟผ๋ฆฌ ํ๋ผ๋ฏธํฐ๋ ๋ผ์ฐํธ ํ๋ผ๋ฏธํฐ๊ฐ ๋ฎ์ด์ธ ๊ฒ์ด๋ค. ์๋ฅผ ๋ค๋ฉด /post/abc/abc?pid=123๋ผ๋ ๋ผ์ฐํธ๋ ์๋์ ๊ฐ์ ์ฟผ๋ฆฌ ๊ฐ์ฒด๋ฅผ ๊ฐ๋๋ค.
Multiple dynamic route segments work the same way. The page pages/post/[pid]/[comment].js will match the route /post/abc/a-comment and its query object will be:
๋ค์ค ๋์ ๋ผ์ฐํธ ์ธ๊ทธ๋จผํธ๋ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ๋์ํ๋ค. pages/post/[pid]/[comment].js ํ์ด์ง๋ /post/abc/a-comment์ ๋งค์น๋ ๊ฒ์ด๊ณ ์ฟผ๋ฆฌ ๊ฐ์ฒด๋ ์๋์ ๊ฐ๋ค:
Client-side navigations to dynamic routes are handled with next/link. If we wanted to have links to the routes used above it will look like this:
๋์ ๊ฒฝ๋ก์ ๋ํ ํด๋ผ์ด์ธํธ ์ธก ๋ค๋น๊ฒ์ด์ ์ next/link๋ก ์ฒ๋ฆฌ๋๋ค. ์์ ๋์จ ๊ฒฝ๋ก๋ค์ ๋ํ ๋งํฌ๋ค์ ์ํ ๋ ์๋์ ๊ฐ์ด ๋ณด์ฌ์ง ๊ฒ์ด๋ค:
Read our docs for Linking between pages to learn more.
๋ ์์๋ณด๋ ค๋ฉด Linking between pages๋ฅผ ์ํ ํ์ด์ง๋ฅผ ์ฝ์ด๋ณด๋ผ.
Catch all routes
Dynamic routes can be extended to catch all paths by adding three dots (...) inside the brackets. For example:
- pages/post/[...slug].js matches /post/a, but also /post/a/b, /post/a/b/c and so on.
๋์ ๊ฒฝ๋ก๋ ์ 3๊ฐ๋ฅผ (...) ๋๊ดํธ ์์ ์ถ๊ฐํ์ฌ ๋ชจ๋ ๊ฒฝ๋ก๋ฅผ ๋ค ํฌํจํ๋๋ก ํ์ฅ๋ ์ ์๋ค. ์๋ฅผ ๋ค๋ฉด:
- pages/post/[...slug].js ๋ /post/a ์ ๋งค์นญ๋์ง๋ง, /post/a/b, /post/a/b/c ๋ ๋ชจ๋ ๋งค์นญ๋๋ค.
Note: You can use names other than slug, such as: [...param]
๋ ธํธ: slug๋ง๊ณ ๋ [...param]๊ณผ ๊ฐ์ ๋ค๋ฅธ ์ด๋ฆ์ ์ฌ์ฉํ ์๋ ์๋ค.
Matched parameters will be sent as a query parameter (slug in the example) to the page, and it will always be an array, so, the path /post/a will have the following query object:
๋งค์น๋๋ ํ๋ผ๋ฏธํฐ๋ค์ ์ฟผ๋ฆฌ ํ๋ผ๋ฏธํฐ๋ก ํ์ด์ง๋ก ๋ณด๋ด์ง ๊ฒ์ด๋ค. (์์์ ๋์ค๋ slug) ํ๋ผ๋ฏธํฐ๋ ํญ์ ๋ฐฐ์ด์ด๋ค. /post/a ๋ ์๋์ ๊ฐ์ ์ฟผ๋ฆฌ ๊ฐ์ฒด๋ฅผ ๊ฐ๋๋ค.
And in the case of /post/a/b, and any other matching path, new parameters will be added to the array, like so:
๊ทธ๋ฆฌ๊ณ /post/a/b์ ๊ฒฝ์ฐ์๋ ๋ ๋ค๋ฅธ ๋งค์น๋๋ ๊ฒฝ๋ก๋ก ์๋ก์ด ํ๋ผ๋ฏธํฐ๋ ๋ฐฐ์ด์ ์ด์ฒ๋ผ ์ถ๊ฐ๋ ๊ฒ์ด๋ค.:
Optional catch all routes
Catch all routes can be made optional by including the parameter in double brackets ([[...slug]]).
For example, pages/post/[[...slug]].js will match /post, /post/a, /post/a/b, and so on.
The main difference between catch all and optional catch all routes is that with optional, the route without the parameter is also matched (/post in the example above).
The query objects are as follows:
์ด์ค ๊ดํธ ์์ ํ๋ผ๋ฏธํฐ๋ฅผ ํฌํจํ์ฌ ๋ชจ๋ ๋ผ์ฐํธ๋ฅผ ์ ํ์ ์ผ๋ก ํฌํจํ ์ ์๋ค.
์๋ฅผ ๋ค๋ฉด pages/post/[[...slug]].js ๋ /post, /post/a, /post/a/b ๋ชจ๋ ๋งค์น๋ ๊ฒ์ด๋ค.
๋ชจ๋ ๊ฒฝ๋ก๋ฅผ ํฌํจํ๋ ๊ฒ๊ณผ ์ ํ์ ์ผ๋ก ๋ชจ๋ ๊ฒฝ๋ก๋ฅผ ํฌํจํ๋ ๊ฒ์ ์ฃผ๋ ์ฐจ์ด์ ์ ํ๋ผ๋ฏธํฐ๊ฐ ์๋ ๊ฒฝ๋ก๋ ๋งค์น๊ฐ ๋๋ค๋ ๊ฒ์ด๋ค. (์์ ์์์ ๋์ค๋ /post์ ๊ฐ์ ๊ฒ)
์ฟผ๋ฆฌ ๊ฐ์ฒด๋ ์๋์ ๊ฐ๋ค:
Caveats
- Predefined routes take precedence over dynamic routes, and dynamic routes over catch all routes. Take a look at the following examples:
์ฌ์ ์ ์๋ ๊ฒฝ๋ก๋ ๋์ ๊ฒฝ๋ก๋ณด๋ค ์ฐ์์ด๋ฉฐ ๋์ ๊ฒฝ๋ก๋ ๋ชจ๋ ๊ฒฝ๋ก๋ฅผ ํฌ์ฐฉํ๋ ๊ฒ๋ณด๋ค ์ฐ์์ด๋ค. ์๋์ ์์๋ค์ ๋ณด๋ผ:- pages/post/create.js - Will match /post/create
- pages/post/[pid].js - Will match /post/1, /post/abc, etc. But not /post/create
- pages/post/[...slug].js - Will match /post/1/2, /post/a/b/c, etc. But not /post/create, /post/abc
- Pages that are statically optimized by Automatic Static Optimization will be hydrated without their route parameters provided, i.e query will be an empty object ({}).
Automatic Static Optimization์ ์ํด ์ ์ ์ผ๋ก ์ต์ ํ๋ ํ์ด์ง๋ ์ ๊ณต๋ ๊ฒฝ๋ก ํ๋ผ๋ฏธํฐ์์ด hydrate๋ ๊ฒ์ด๋ค. query๋ ๋น ๊ฐ์ฒด์ผ ๊ฒ์ด๋ค. - After hydration, Next.js will trigger an update to your application to provide the route parameters in the query object.
hydration* ํ์ Next.js๋ ์ดํ๋ฆฌ์ผ์ด์ ์ ๋ฐ์ดํฐ๋ฅผ ํธ๋ฆฌ๊ฑฐํ์ฌ ์ฟผ๋ฆฌ ๊ฐ์ฒด์ ๊ฒฝ๋ก ํ๋ผ๋ฏธํฐ๋ฅผ ์ ๊ณตํ๋ค.*Hydration: Each generated HTML is associated with minimal JavaScript code necessary for that page. When a page is loaded by the browser, its JavaScript code runs and makes the page fully interactive. (This process is called hydration.)
๊ฐ ์์ฑ๋ HTML ํ์ด์ง (ํ์ด์ง์ ํ์ํ ์ต์ํ์ ์๋ฐ์คํฌ๋ฆฝํธ ์ฝ๋์ ์ฐ๊ฒฐ๋์ด ์๋)๊ฐ ๋ธ๋ผ์ฐ์ ์ ๋ก๋๋๋ฉด ์๋ฐ์คํฌ๋ฆฝํธ ์ฝ๋๊ฐ ์คํ๋๊ณ ํ์ด์ง๊ฐ ์์ ํ ์ธํฐ๋ํฐ๋ธํ๊ฒ ๋๋ ๊ณผ์ .
Imperatively
next/link should be able to cover most of your routing needs, but you can also do client-side navigations without it, take a look at the documentation for next/router.
The following example shows how to do basic page navigations with useRouter:
next/link๊ฐ routing์ ํ์ํ ๊ฑฐ์ ๋๋ถ๋ถ์ ๊ฒ์ ์ปค๋ฒํ ์ ์์ด์ผ ํ์ง๋ง next/link ์์ด ํด๋ผ์ด์ธํธ ์ธก์์ ์ด๋ํ๋ ๊ฒ๋ ๊ฐ๋ฅํ๋ค. next/router ๋ฌธ์๋ฅผ ์ฐธ์กฐํ๋ผ.
์๋์ ์์ ๋ useRouter๋ก ์ด๋ป๊ฒ ๊ธฐ๋ณธ์ ์ธ ํ์ด์ง ๋ค๋น๊ฒ์ด์ ์ด ๊ฐ๋ฅํ์ง ๋ณด์ฌ์ค๋ค.
Shallow Routing
Shallow routing allows you to change the URL without running data fetching methods again, that includes [getServerSideProps](<https://nextjs.org/docs/basic-features/data-fetching#getserversideprops-server-side-rendering>), [getStaticProps](<https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation>), and [getInitialProps](<https://nextjs.org/docs/api-reference/data-fetching/getInitialProps>).
You'll receive the updated pathname and the query via the [router object](https://nextjs.org/docs/api-reference/next/router#router-object) (added by [useRouter](<https://nextjs.org/docs/api-reference/next/router#userouter>) or [withRouter](<https://nextjs.org/docs/api-reference/next/router#withrouter>)), without losing state.
To enable shallow routing, set the shallow option to true. Consider the following example:
Shallow routing์ getServerSideProps, getStaticProps, getInitalProps ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๋ ๋ฉ์๋๋ฅผ ๋ค์ ๋์์ํค์ง ์๊ณ ๋ URL ๋ณ๊ฒฝ์ ๊ฐ๋ฅํ๊ฒ ํด์ค๋ค.
์ ๋ฐ์ดํธ๋ pathname๊ณผ query๋ฅผ ์ํ๋ฅผ ์์ง์๊ณ router ๊ฐ์ฒด๋ฅผ ํตํด์(useRouter๋ withRouter์ ์ํด ์ถ๊ฐ๋) ๋ฐ์ ๊ฒ์ด๋ค.
Shallow routing์ ์ฌ์ฉํ๋ ค๋ฉด shallow ์ต์ ์ true๋ก ์ฃผ์ด์ผํ๋ค. ์๋์ ์์ ๋ฅผ ๊ณ ๋ คํด๋ณด๋ผ:
The URL will get updated to /?counter=10. and the page won't get replaced, only the state of the route is changed.
You can also watch for URL changes via componentDidUpdate as shown below:
URL์ conter=10์ผ๋ก ์ ๋ฐ์ดํธ ๋ ๊ฒ์ด๋ค. ํ์ด์ง๋ ๋์ฒด๋์ง ์์ ๊ฒ์ด๊ณ ๋ผ์ฐํธ์ ์ํ๋ง ๋ณ๊ฒฝ๋ ๊ฒ์ด๋ค.
์๋์ ๊ฐ์ด URL์ด ๋ณ๊ฒฝ๋๋ ๊ฒ์ componentDidUpdate๋ฅผ ํตํด์๋ ํ์ธํ ์ ์๋ค
Caveats
Shallow routing only works for same page URL changes. For example, let's assume we have another page called pages/about.js, and you run this:
Shallow routing์ ๋์ผํ ํ์ด์ง์ URL ๋ณ๊ฒฝ์ ๋ํด์๋ง ๋์ํ๋ค. ์๋ฅผ ๋ค์ด pages/about.js ๋ผ๋ ๋ค๋ฅธ ํ์ด์ง๊ฐ ์๋ค๊ณ ํ๊ณ ์ด๊ฒ์ ์คํํ๋ฉด:
Since that's a new page, it'll unload the current page, load the new one and wait for data fetching even though we asked to do shallow routing.
์ด๊ฒ์ ์๋ก์ด ํ์ด์ง์ด๊ธฐ ๋๋ฌธ์ ํ์ฌ ํ์ด์ง๋ ์ธ๋ก๋๋๊ณ ์๋ก์ด ํ์ด์ง๊ฐ ๋ก๋๋๊ณ shallow routing์ ์์ฒญํ๊ธด ํ์ง๋ง ๋ฐ์ดํฐ๊ฐ ํจ์น๋๋ ๊ฒ์ ๊ธฐ๋ค๋ฆด ๊ฒ์ด๋ค.
'Next.js' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ด๋ณด๋ด๋ฒ] Next.js docs - next/image (0) | 2021.04.01 |
---|---|
[๋ด๋ณด๋ด๋ฒ] Next.js docs - Image Component and Image Optimization (0) | 2021.03.31 |
[๋ด๋ณด๋ด๋ฒ] Next.js docs - Built-In CSS Support (0) | 2021.03.31 |
[๋ด๋ณด๋ด๋ฒ] Next.js docs - Data Fetching (0) | 2021.03.30 |
[๋ด๋ณด๋ด๋ฒ] Next.js docs - Pages (0) | 2021.03.29 |