[英]getInitialProps is not called when visiting directly the page url in nextjs
[英]How to deal with slow load page in nextjs when using getInitialProps?
我正在使用nextjs 9
和redux
。這是我的應用程序的頁面:
import React from 'react';
import { useRouter } from 'next/router';
import { ShowDataCmp } from '../../components';
import { getData } from '../../store/SamplePage/SamplePageAction';
const SamplePage = () => {
const router = useRouter();
return <ShowDataCmp query={router.query} />;
};
SamplePage.getInitialProps = async ({ store }) => {
const config = {
start_date: '1991-10-22',
end_date: '2019-10-22',
};
await store.dispatch(
getData(config),
);
};
export default SamplePage;
我想獲取一些數據並dispatch an action
來將數據存儲在redux
中。
然后我使用ShowDataCmp
中的數據。我需要它在服務器端,以便數據在頁面資源中,所以我必須在這里獲取數據。 但是因為我的 fetch API 有點慢,所以頁面加載會很慢。
是否有任何解決方案來補償頁面緩慢的加載時間?
嘗試在您的_app
頁面或layout
組件中實現加載屏幕並優化getData
function
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.