Pass params from getStaticPaths to getStaticProps, which is not binded to route parameter?

Viewed 66

The SSG documentation recommends to fetch the data for the list of path params in getStaticPaths and fetch data for the individual pages in getStaticProps.

This is the route path:

[postId]/[tempUserShortId]/index.tsx

Except postId and tempUserShortId I tried to pass organizationShortId and imgId, but seems they are not available in getStaticProps.

export const getStaticPaths: GetStaticPaths = async () => {
    axios.defaults.baseURL = baseURL(
        process.env.NEXT_PUBLIC_ENVIRONMENT ?? 'dev',
        false
    )
    const res = await axios({
        method: 'get',
        url: 'organizationShortIdPostIdTempUserShortIdAndImgIdList',
    })
    const paths = res.data.map((organizationAndPostId: string) => ({
        params: {
            organizationShortId: organizationAndPostId[0],
            postId: organizationAndPostId[1],
            tempUserShortId: organizationAndPostId[2],
            imgId: organizationAndPostId[3],
        },
    }))

here, not available. Is it any trick to get them. They make easier backend query to execute.

export const getStaticProps: GetStaticProps = async ({ ...context }) => {
    let organizationShortId: string = context.params
        ?.organizationShortId as string
    let postId: string = context.params?.postId as string
    let tempUserShortId: string = context.params?.tempUserShortId as string
    axios.defaults.baseURL = baseURL(
        process.env.NEXT_PUBLIC_ENVIRONMENT ?? 'dev',
        false
    )
0 Answers
Related