invalid-redirect-gssp.mdx


title: '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.

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
}
export async function getStaticPaths() {
  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 } }
}

export default function Page({ repo }) {
  return repo.stargazers_count
}

Rendered from the public repository vercel/next.js on GitHub; content belongs to its authors. Cached for up to an hour.

errors/invalid-redirect-gssp.mdx · vercel/next.js | Docs MD