【问题标题】:How to to use context.query with getServerSideProps()? | NextJS如何将 context.query 与 getServerSideProps() 一起使用? |下一个JS
【发布时间】:2023-02-23 02:33:08
【问题描述】:

我的 NextJS 应用程序上的 getServerSideProps() 遇到问题。

基本上,我将 nft 集合的数据(名称、描述、地址等)手动从内部 json 传递到单击的集合的 url。当用户单击集合时动态薄荷页面渲染router.query的数据。

我已经在 Mint 页面组件中成功地将其转换为 useEffectrouter.query。但是当我试图用 getServerSideProps() 对于 SSR,context.query 没有任何返回(下面的函数)

export async function getServerSideProps(context) {
  const mint = context.query;
  return { props: { mint } };
}

这是 getServerSideProps() 下面的 MintSection 组件

function MintSection({ mint }) {
  console.log(mint);

  other code
  ...

}

【问题讨论】:

标签: reactjs next.js server-side-rendering


【解决方案1】:

使用解构。

const {mint} = context.query;

【讨论】:

    猜你喜欢
    • 2021-08-04
    • 2021-08-06
    • 2022-01-15
    • 2022-01-09
    • 2021-05-22
    • 2020-11-30
    • 1970-01-01
    • 2018-01-17
    • 2014-05-18
    相关资源
    最近更新 更多