How to get the id of a dynamic route with Nextjs’ getServerSideProps

off.tokyo
Jun 26, 2021

--

## Things to do

Normally, in order to get the id 1 in Next.js dynamic routing (post/1), you can write the following to get the value.

```js
const { id } = router.query;
```

How do I get this in getServerSideProps?

```js
export async function getServerSideProps(context) {
```

You can do the following to get it.

```js

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

## Reference.

[Dynamic routing with getServerSideProps in Nextjs](https://stackoverflow.com/questions/61222726/dynamic-routing-with- getserversideprops-in-nextjs)

[How to get the id of dynamic routing with getServerSideProps in Nextjs](https://off.tokyo/blog/dynamic-routing-with-getserversideprops-in-nextjs/)

--

--

No responses yet