Skip to content
DocsErrorsInvalid Redirect `getStaticProps` / `getServerSideProps`

Invalid Redirect `getStaticProps` / `getServerSideProps`

Why This Error Occurred

The redirect value returned from your getStaticProps or getServerSideProps function had invalid values.

Possible Ways to Fix It

Make sure you return the proper values for the redirect value.

pages/index.tsx
import type { InferGetStaticPropsType, GetStaticProps } from 'next'
 
type Repo = {
  name: string
  stargazers_count: number
}
 
export const getStaticProps = (async (context) => {
  const res = await fetch('https://api.github.com/repos/vercel/next.js')
  const repo = await res.json()
 
  if (!repo) {
    return {
      redirect: {
        permanent: false, // or true
        destination: '/404',
      },
    }
  }
 
  return { props: { repo } }
}) satisfies GetStaticProps<{
  repo: Repo
}>
 
export default function Page({
  repo,
}: InferGetStaticPropsType<typeof getStaticProps>) {
  return repo.stargazers_count
}