I have a file like blog-details/[id].tsx
. And I am trying to navigate via:
<Link href={`/blog-details/${item._id}.tsx`}>`
After the page navigates, I need to fetch the data from db using the id
, but the issue here is I am unable to access context.params
from getServerSideProps
.
const getServerSideProps = async (context) => {
const params = context.params;
console.log('route params ', params); // This doesn't get logged on page route
}
2
Answers
You can try
First, make sure you are exporting
getServerSidePros
from/blog-details/[id].tsx
file:Then you don’t need to add this
.tsx
at the end of the URL:Unless you want to get a
someId.tsx
.