Kam*_*lam 3 javascript ecmascript-6 reactjs es6-modules next.js
我正在尝试将 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: {},
};
};
Run Code Online (Sandbox Code Playgroud)
Kam*_*lam 12
我找到了答案。这是如何在另一个页面上使用页面数据获取方法的方法
import DashboardLayout from "@app/layout/DashboardLayout";
import MyCourses from "@containers/dashboard/MyCourses";
import { getServerSideProps } from "../index";
const MyCoursesPage = () => {
return (
<DashboardLayout>
<MyCourses />
</DashboardLayout>
);
};
export default MyCoursesPage;
export { getServerSideProps };
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6241 次 |
| 最近记录: |