ReasonJun

Next.js : File System-based Routing (Dynamic Routing ) 본문

Frontend/Next.js

Next.js : File System-based Routing (Dynamic Routing )

ReasonJun 2023. 6. 18. 18:40
728x90

Dynamic Routing

pages/product/first-item

pages/category/[slug].js => /category/:slug (ex. /category/food )

pages/[username]/info.js => /:username/info (ex. /youjun/info )

pages/cart/[...slug].js => /cart/* (ex. /cart/2022/06/24 )

useRouter / query

Multiple Slug

pages/[username]/[info].js

const { username, info } = router.query

 

pages/cart/[...slug].js

const { slug } = router.query

=> array

 

Optional Slug

pages/cart/[]...slug.js => Accessing '/cart' results in 404.

pages/cart/[[...slug]].js => It is received even if the slug does not exist. The default page is displayed.

 

 

 

728x90

'Frontend > Next.js' 카테고리의 다른 글

Next.js : API Routes  (0) 2023.06.18
Next.js : File System-based Routing (Shallow Routing)  (0) 2023.06.18
Next.js : Apply common layout  (0) 2023.06.18
Next.js : Image component  (0) 2023.06.18
Next.js : getStaticProps with revalidata (ISR)  (0) 2023.06.18
Comments