提问人:Devanand 提问时间:10/29/2023 更新时间:10/29/2023 访问量:43
当我使用 generateStaticParams 时,重新验证只工作一次
Revalidation is working only once when I use generateStaticParams
问:
我尝试在我的应用程序中实现 ISR,但重新验证只有效一次,并且在重新验证时间后不会更新页面。有时页面变得无法访问,链接不起作用。
这是我的代码 路径 - src/app/games/page.tsx
import GamesHeroSection from "@/components/GamesPage/Sections/GamesHeroSection";
import GamesNewsletter from "@/components/GamesPage/Sections/GamesNewsletter";
import GamesQuotMessage from "@/components/GamesPage/Sections/GamesQuotMessage";
import GamesShowcaseSection from "@/components/GamesPage/Sections/GamesShowcaseSection";
import GamesUpdateSection from "@/components/GamesPage/Sections/GamesUpdateSection";
import GamesServicesSection from "@/components/GamesPage/Sections/GamesServicesSection";
import { GameList } from "@/types/Games";
import { baseUrl } from "@/lib/apiUrl";
type Props = {};
async function getGames() {
const result = await fetch(baseUrl+"/games",{next:{revalidate:60}});
return result.json();
}
const GamesPage = async(props: Props) => {
const data : GameList[] = await getGames(); // only uncomment when backend is connected
return (
<div id="GamesPage"className="select-none" >
<GamesHeroSection />
<GamesQuotMessage />
<GamesServicesSection />
<GamesShowcaseSection gameList={data} />
<GamesUpdateSection />
<GamesNewsletter />
</div>
);
};
export default GamesPage;
第二页
路径 - src/app/games/[id]/page.tsx
import GameViewAboutSection from "@/components/GamesPageView/Sections/GameViewAboutSection";
import GameViewHeroSection from "@/components/GamesPageView/Sections/GameViewHeroSection";
import GameViewScreenshotSection from "@/components/GamesPageView/Sections/GameViewScreenshotSection";
import FaqBox from "@/components/utils/FaqBox";
import { baseUrl } from "@/lib/apiUrl";
import { GameList } from "@/types/Games";
type Props = {};
export async function generateStaticParams() {
const games = await fetch(baseUrl+"/games", {
next: { revalidate: 60 },
}).then((res) => res.json());
return games.map((game: GameList) => ({
id: game._id,
}));
}
async function getGameById(id:string) {
const result = await fetch(baseUrl+`/games/${id}`,{method:"GET",cache:'no-store'})
return result.json()
}
const GamesViewPage = async ({ params }: { params: { id: string } }) => {
const data: GameList = await getGameById(params.id);
return (
<div id="GamesViewPage" className="select-none">
<GameViewHeroSection data={data} />
<GameViewScreenshotSection data={data} />
<GameViewAboutSection data={data} />
<FaqBox data={data.faq} />
</div>
);
};
export default GamesViewPage;
import GameViewAboutSection from "@/components/GamesPageView/Sections/GameViewAboutSection";
import GameViewHeroSection from "@/components/GamesPageView/Sections/GameViewHeroSection";
import GameViewScreenshotSection from "@/components/GamesPageView/Sections/GameViewScreenshotSection";
import FaqBox from "@/components/utils/FaqBox";
import { baseUrl } from "@/lib/apiUrl";
import { GameList } from "@/types/Games";
type Props = {};
export async function generateStaticParams() {
const games = await fetch(baseUrl+"/games", {
next: { revalidate: 60 },
}).then((res) => res.json());
return games.map((game: GameList) => ({
id: game._id,
}));
}
async function getGameById(id:string) {
const result = await fetch(baseUrl+`/games/${id}`,{method:"GET",cache:'no-store'})
return result.json()
}
const GamesViewPage = async ({ params }: { params: { id: string } }) => {
const data: GameList = await getGameById(params.id);
return (
<div id="GamesViewPage" className="select-none">
<GameViewHeroSection data={data} />
<GameViewScreenshotSection data={data} />
<GameViewAboutSection data={data} />
<FaqBox data={data.faq} />
</div>
);
};
export default GamesViewPage;
需要帮助来解决这个问题 后端是一个快速应用程序
我试图每 60 秒重新验证一次游戏页面及其动态路由 [id]/page.tsx,但它只发生一次,之后就不起作用了。
答: 暂无答案
评论