I have a dynamic route. Using generateStaticParams creates static paths for me at build time. So far everything is normal.
However, navigating to a new route in runtime causes that route to be created statically. even if the page returns 404.
This is not a desired situation. Because non-existent routes take up unnecessary cache space.
export dynamicParams = false
When I set the parameter to false, it returns 404 for all routes except the routes during build.
export dynamicParams = true
When I set the parameter to true, it caches every route taken, even if the route returns a 404.
How should I add a new route when the user creates a new page from cms? my code is as below
/app/[[…slug]]/page.js
export const dynamicParams = true;
export default async function generateStaticContent({ params }) {
const { isEnabled } = draftMode();
const config = await getRouteConfig(params, isEnabled);
if(config.error) return notFound();
return produceContent(config);
}
export async function generateStaticParams() {
return produceRoutes();
}