实战建议(续)
// 产品列表:静态 + 按需更新
// app/products/page.tsx
export default async function ProductsPage() {
const res = await fetch("https://api.example.com/products", {
next: { tags: ["products"], revalidate: 3600 },
cache: "force-cache",
});
const products = await res.json();
return <div>...</div>;
}
// 购物车:动态(每个用户不同)
// app/cart/page.tsx
import { cookies } from "next/headers";
export default async function CartPage() {
const token = (await cookies()).get("token")?.value;
const res = await fetch("https://api.example.com/cart", {
headers: { Authorization: `Bearer ${token}` },
});
const cart = await res.json();
return <div>...</div>;
}