2

I'm facing the next situation, I'm using Next.js and I need to manage two different files that will use dynamic routes. The reason is that the site has static and SSR pages, the static ones use getStaticPath and getStaticProps functions and the SSR use getServerSideProps. So Next doesn't allow to have those functions on the same file and that's why I can't have just one file that renders different page components or some logic to manage ssr or static.

Expected:

mysite.com/[...slug] will be for static page

mysite.com/[...category] will be for ssr page

All pages come from a wordpress CMS and their url structure cannot be changed. I mean the ssr url page from mini example above can't be mysite.com/etc/[...category]

Alejandro
  • 21
  • 1
  • 1
    That's not possible with Next.js built-in routing. Next.js uses a [file-system based routing](https://nextjs.org/docs/routing/introduction), if both dynamic routes are on the same level it wouldn't know what path to match. You'll have to use a different folder structure. – juliomalves Oct 13 '21 at 17:23
  • I had the same situation and ended up using conditional rendering. `if url param is category => render ssr page, else render static page` – Shahriar Aug 27 '23 at 18:15

0 Answers0