LoginSignup
0
0

More than 1 year has passed since last update.

NextjsのgetServerSidePropsでダイナミックルーティングのidを取得する方法

Posted at

やること

通常、Next.jsのダイナミックルーティング(post/1)ではidの1を取得するためには、下記のように書くと値がとれます。

const { id } = router.query;

これをgetServerSidePropsの中で取得するにはどうすればいいでしょうか。

export async function getServerSideProps(context) {

下記のようにすれば取れます。


export async function getServerSideProps(context) {
  const { id } = context.query;

参考

Dynamic routing with getServerSideProps in Nextjs

NextjsのgetServerSidePropsでダイナミックルーティングのidを取得する方法

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0