How can I use getStaticProps with `next export` for a dynamically routed page?
Unanswered
Holland Lop posted this in #help-forum
Holland LopOP
I want to use getStaticProps to get translation data for a page
- When adding
- Returning
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
I'm following this template: https://github.com/i18next/next-i18next/tree/master/examples/ssg
Holland LopOP
Seemingly fixed by using:
{ paths: [], fallback: false }@Holland Lop I'm following this template: https://github.com/i18next/next-i18next/tree/master/examples/ssg
Northeast Congo Lion
u can use
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 URLsnextjs 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 routerjust not the exact same function
Holland LopOP
Ok, thank you