未在导入的 Nextjs 页面上调用 getServerSideProps

时间:2021-05-12 15:25:10

标签: next.js getserversideprops

有没有其他人遇到过在 Nextjs 中导入的组件没有调用 getServerSideProps 的问题,我需要帮助!

我省略了一些逻辑,但重点是每当我将优惠券页面导入布局页面时,除非我访问 localhost:3000/coupon,否则不会调用 getServerSideProps

这是我的优惠券页面


const Coupon = () => {
  return (
    <div>
      <p>Hello</p>  
    </div>
  );
};

// coupon page
export async function getServerSideProps(context) {
  console.log(context);
  console.log("here");

  return {
    props: {}, // will be passed to the page component as props
  };
}
export default Coupon;

和我的布局页面

import Coupon from './coupon'

const Layout = () => {
  return (
    <div>
      <Coupon />
    </div>
  );
};

export default Layout;

0 个答案:

没有答案