I have a dynamic route and I am trying to show the title in url and pass (hide) the id to my dynamic route and use id
in getStaticProps
. I have found that I can't pass data easily in nextjs as we used to pass with react router or other client routing libraries.
I am following this answer but when I console.log(context.params)
I can't see the id
passed from Link
, what am I doing wrong here ?
// index.js
<Link
href={{
pathname: `/movie/[title]`,
query: {
id: movie.id, // pass the id
},
}}
as={`/movie/${movie.original_title}`}
>
<a>...</a>
</Link>
// [movieId].js
export async function getStaticProps(context) {
console.log(context.params); // return { movieId: 'Mortal Kombat' }
return {
props: { data: "" },
};
}