在Nextjs13中使用context.query

qf9go6mv  于 2023-06-22  发布在  其他
关注(0)|答案(1)|浏览(100)

看起来我在Nextjs 12中使用的context.query在13中不起作用。我应该用什么来代替context.query?上下文API?useSearchParams?我仍然是一个新手开发者,我很失落。
这是我在Next js 12中使用的代码(getServerSideProps已经在新的next13项目中使用):

export const getServerSideProps: GetServerSideProps = async (context) => {
  let curso: any;
  let { id, type }: any = context.query;

  curso = await treatCursoData(curso, id, type);

  if (!curso) return { notFound: true };

  return { props: { curso, type: type || null } };
};

我只尝试使用SearchParams,但无法使它工作。
非常感谢你的任何帮助:)

相关问题