#2 nested dynamic paths/routes?

5 messages · Page 1 of 1 (latest)

toxic shell
#

(disclaimer: i dont think this is an api route question per say, but im a beginner so maybe it is?)

trying to use a dynamic route of localhost:3000/[company_name]/[event_id]

for ex, i'd like to be able to reach localhost:3000/Blah-Company/1

folder structure is image #1, and this is what im trying to do in [event_id].jsx:

export const getStaticPaths = async () => {
    return {
        paths: [{ params: { company_name: '1' } }, { params: { event_id: '2' } }],
        fallback: false, // can also be true or 'blocking'
    }
}

export async function getStaticProps(context) {
    console.log('context: ', context);
    return {
        // Passed to the page component as props
        props: { post: {} },
    }
}

export default function Test({ post }) {
    return (
        <div className="min-h-screen bg-white secondary font-Inter_rsms">
            <p>test</p>
        </div>
    )
}

but im being thrown this error: Error: A required parameter (event_id) was not provided as a string in getStaticPaths for /[company_name]/[event_id] while on localhost:3000/Blah-Company/1

misty locust
#

each object in paths should have all the params necessary in the route

#

the code is creating separate objects, each with one of the required slugs, but not both of them at the same time

#

you need to have them together: { params: { company_name: '1', event_id: '2' } }

toxic shell
#

thank you!