react-next-boilerplate icon indicating copy to clipboard operation
react-next-boilerplate copied to clipboard

merge index and slug routes into one file

Open dohomi opened this issue 3 years ago • 1 comments

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 

dohomi avatar May 06 '21 03:05 dohomi

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.

lisilinhart avatar Jun 11 '21 07:06 lisilinhart