Next.js Discord

Discord Forum

How can I use getStaticProps with `next export` for a dynamically routed page?

Unanswered
Holland Lop posted this in #help-forum
Open in Discord
Holland LopOP
I want to use getStaticProps to get translation data for a page app/[[...path]].js that is dynamically routed.
- When adding getStaticProps I get: getStaticPaths is required for dynamic SSG pages and is missing for '/app/[[...path]]'
- Returning { paths: [], fallback: true } from getStaticPaths does not work as it is not supported by next export.

14 Replies

Holland LopOP
The reason I want getStaticProps is for translations:
export const getStaticProps = async ({ locale }) => ({
    props: {
        ...(await serverSideTranslations(locale, ['translation'])),
    },
});
Holland LopOP
Holland LopOP
Seemingly fixed by using: { paths: [], fallback: false }
export async function generateStaticParams() {

    const slugsReq = await fetch(url_to_fetch_paths);
    const slugRes = await slugsReq.json();

    return slugRes.filter((slug) => {
      return {
        '...slug': slug.path
      }
    });
}
something like this function. WHere url_to_fetch_paths is a url or json feed that returns a list of ur page URLs
nextjs needs to know what the URLs will be for these dynamic paths if u want to pre-render.
if u don't know url, then it will be unique and use Serverside generation.
Holland LopOP
This API requires the app structure?
Northeast Congo Lion
yes, are you using pages.
it is still possible with pages router
just not the exact same function
Holland LopOP
Ok, thank you