Adding new pages without generate a build

Hey,

I’m working on a dynamic page that supports the creation of unlimited new posts (pages) based on the CMS data model. In cases where the specific post data does not exist, I need to return a 404 page.

Here are the implementation steps I’ve taken:

  1. In Builder, I created a dynamic page that targets all pages starting with ‘/post.’

  2. Additionally, I created a CMS data model from which the dynamic page fetches the selected post data using custom JS.

  3. In my Next.js app, I created a dynamic page with the ‘getStaticPaths’ fallback value set to ‘true.’

The current issue is that using ‘getStaticPaths’ and setting the fallback value to ‘blocking’ will work as I expect, but it will require me to generate a build each time new posts are added.

On the other hand, setting the ‘getStaticPaths’ value to ‘true’ will show a page even if the post IDs do not really exist, and some of the data shown may be broken.

What would be the best way to implement this?

Hi @yuval222, We have a default 404 page that you can use, which you can see an example of in our NextJS starter examples here: builder/[[…page]].tsx at 2e199acfe6979ec799724898cdc8b4243e5b1827 · BuilderIO/builder · GitHub

If you wanted to create a custom 404 page within the builder then I would recommend making a new page or section model, which you can call “error-page” or whatever you like, and then based on the logic linked above, instead of the default error page you could do something like:

 if (!page && isLive) {
    return (
      <>
        <BuilderComponent model="error-page"  />
      </>
    )
  }

  return (
    <>
      <BuilderComponent model="page" />
    </>
  )
}

Related post: How do I customize the 404 page for different urls?

Let me know if that makes sense and works for you!