【发布时间】:2023-02-23 02:33:08
【问题描述】:
我的 NextJS 应用程序上的 getServerSideProps() 遇到问题。
基本上,我将 nft 集合的数据(名称、描述、地址等)手动从内部 json 传递到单击的集合的 url。当用户单击集合时动态薄荷页面渲染与router.query的数据。
我已经在 Mint 页面组件中成功地将其转换为 useEffect 和 router.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
...
}
【问题讨论】:
-
MintSection是页面组件吗?请记住,getServerSideProps仅在页面组件中运行,它不会在常规组件中运行。见NEXTJS: getServerSideProps not working into components。
标签: reactjs next.js server-side-rendering