nextjs - dynamic route with [...mydynamicroute].tsx
Nextjs dynamic route are different from APP and PAGES.
For example the following are setup for app router
App Route definition
/app/product/[slug]/page.tsx
Request for:
/product/a -> OK
/product/b -> OK
/product/a/b -> Not Ok - To support this your need to define route with something like this
/app/product/[...slug]/pages.tsx
The test contents for file are shown here
Page router
Notice page router uses "useRouter" and catch all segment uses [..page].ts (file - not folder).
So we place this under /page/shop/[slug].tsx - Not /pages/api/shop -> that's something else and the intention is for API.
Our dynamic route definition is like this
/page/shop/[slug].tsx
Request for
pages/shop/a --> Ok
pages/shop/b -> Ok
pages/shop/a/b -> Not Ok -> It returns 404. To accommodate this, then we do something like /pages/shop/[...slug].tsx
Comments