Skip to content

Commit

Permalink
switch dynamic strapi routes to SSR rather than SSG
Browse files Browse the repository at this point in the history
  • Loading branch information
Woozl committed Mar 3, 2023
1 parent dbd3d6b commit 5a447d9
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions pages/[...slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,7 @@ const DynamicPage = ({
)
}

export async function getStaticPaths(context) {
// Get all pages from Strapi
const allPages = context.locales.map(async (locale) => {
const localePages = await fetchAPI(`/api/pages`)
return localePages
})

const pages = await (await Promise.all(allPages)).flat()

const paths = pages.map((page) => {
// Decompose the slug that was saved in Strapi
// const slugArray = !page.data[0].attributes.slug ? false : page.data[0].attributes.slug.split("/")
return {
params: { slug: [page.data[0].attributes.slug] },
// Specify the locale to render
locale: page.locale,
}
})

return { paths, fallback: true }
}

export async function getStaticProps(context) {
export async function getServerSideProps(context) {
const { params, locale, locales, defaultLocale, preview = null } = context

const globalLocale = await getGlobalData(locale)
Expand Down

0 comments on commit 5a447d9

Please sign in to comment.