storyblok / react-next-boilerplate

Nextjs Storyblok boilerplate
https://www.storyblok.com/tp/add-a-headless-cms-to-next-js-in-5-minutes
64 stars 34 forks source link

merge index and slug routes into one file #12

Open dohomi opened 3 years ago

dohomi commented 3 years ago

Hello,

I think for micro optimization it would be better to merge index, [slug] and [...slug] into one file:

[[...index]].jsx // or [[...index]].tsx

NextJS handles double square brackets as catch all route and you can merge all content into one file rather than keeping 3 separate files

Now the only adjustment to make is inside getStaticProps

export getStaticProps: GetStaticProps<AppPageProps> = async (props) => {
  const { params, preview, previewData, locale, locales, defaultLocale } = props
  const slug = params?.index?.length
    ? params.index !== 'index'
      ? params.index
      : 'home'
    : 'home'
  (...) // all other content 
lisilinhart commented 3 years ago

Thanks, I merged [slug] into [...slug]. But will keep index.js for now, to have a static page example that is not using catch-all routes.