This question may seem basic, but I can't seem to find the answer anywhere online.
Currently, I am diving into NextJs (using TypeScript) and I have successfully set up a site with dynamic routes, SSR, and incremental regeneration deployed on Vercel. Below is an example of the code in my dynamic route handler for GetStaticProps
and GetStaticPaths
:
export const getStaticPaths: GetStaticPaths = async () => {
const routes = new CmsHelper().GetRoutes();
const paths = (await routes).items.map((item, index, items) => {
return item.fields.urlPath;
})
return {
paths: paths,
fallback: 'blocking',
};
}
export const getStaticProps: GetStaticProps = async (context) => {
const urlParts = context.params?.url as string[] || [];
const urlPath = `/${urlParts.join('/')}`;
const article = await new CmsHelper().GetArticle(urlPath);
return {
props: {
article
},
revalidate: 10,
}
}
If I request a new path added after build time in the CMS, it regenerates successfully and shows the page.
Everything seems fine so far.
However, if I unpublish a route in the CMS... it still shows up in the app unless I rebuild and redeploy (in development).
So here's my question: how can I dynamically remove a dynamic route from NextJs' GetStaticPaths cache?
I know that GetStaticProps
is called at most once every 10 seconds due to the revalidate
setting. But as far as I understand, GetStaticPaths
is only triggered when a request comes in from a route that is not already cached(?).
In essence, for integration with a headless CMS, how can I handle unpublishing or renaming pages in NextJs without needing a rebuild/deploy?
Thank you in advance!