getServerSideProps 上的 next.js 重定向抛出有关道具的错误

时间:2021-05-13 19:08:50

标签: reactjs next.js

如果我的表达失败,我只是想从这个页面重定向到另一个页面。我阅读了文档,完全按照他们所做的去做,在网上查看了他们所做的事情,而且我每次都得到这个。

Error: Additional keys were returned from `getServerSideProps`. Properties intended for your component must be nested under the `props` key, e.g.:

    return { props: { title: 'My Title', content: '...' } }

Keys that need to be moved: redirect.
Read more: https://err.sh/next.js/invalid-getstaticprops-value
This error happened while generating the page. Any console logs will be displayed in the terminal window.

这是我在页面内的代码

export async function getServerSideProps(req) {
  if(req){
    return {
      redirect: {
        permanent: false,
        destination: "/"
      }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

根据您的代码,您希望一直临时重定向到基本 URL。如果是这种情况,那么在 module.exports = { async redirects() { return [ { source: '/your-page', // whatever your page is destination: '/', permanent: false, }, ] }, }

中定义逻辑是有意义的
BatchDataset

参考

https://nextjs.org/docs/api-reference/next.config.js/redirects