I'm new to Next.js and trying to use the new app router (i.e. place my pages under app/.../page.tsx)
The following works in page router (pages/blah.tsx) but not in app/blah/page.tsx . app router doesn't call getServerSideProps at all and passes empty params to the page function.
Why? How do I use getServerSideProps in app router?
import type { InferGetServerSidePropsType, GetServerSideProps } from 'next'
type Repo = {
name: string
stargazers_count: number
}
export const getServerSideProps: GetServerSideProps<{
repo: Repo
}> = async () => {
const res = await fetch('https://api.github.com/repos/vercel/next.js')
const repo = await res.json()
return { props: { repo } }
}
export default function Page({
repo,
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
return <div>{repo.stargazers_count}</div>
}