【发布时间】:2022-01-10 23:28:43
【问题描述】:
我正在尝试将 getServerSideProps 方法从该页面导入到另一个页面,并在多个页面中使用它。我该怎么做?
这是我的代码:
import DashboardLayout from "@app/layout/DashboardLayout";
import Overview from "@containers/dashboard/Overview";
import { parsedCookie } from "@infrastructure/utils/functions";
const OverviewPage = () => {
return (
<DashboardLayout>
<Overview />
</DashboardLayout>
);
};
export default OverviewPage;
export const getServerSideProps = async (context) => {
const token = parsedCookie(context.req);
const { accessToken, refreshToken } = token;
if (!accessToken || !refreshToken) {
return {
redirect: {
destination: "/",
permanent: false,
},
};
}
return {
props: {},
};
};
【问题讨论】:
-
将此函数放在一个单独的文件中,并在需要的地方导入。
标签: javascript reactjs ecmascript-6 next.js es6-modules