我需要生成元数据并使用 仅一个请求渲染页面,我想使用一个请求,因为我正在构建一个博客页面,多个请求或缓存会导致 viewCounter 计数不正确
我当前的代码
获取博客功能
export async function getTurkishPostBySlug(TrSlug) {
const res = await fetch(`http://localhost:8080/post/${TrSlug}`, { cache: "no-store" })
if (res.status === 200) {
return res.json()
} else {
return "err"
}
}
Page.js
export async function generateMetadata({ params, searchParams }, parent) {
const res = await getTurkishPostBySlug(params.slug)
if (res.blog) {
return {
title: res.blog.TR_title,
}
}
}
async function CodeDetail({params}) {
let post = null
let res = await getTurkishPostBySlug(params.slug)
if (res.blog) {
post = res.blog
}
if (post) {
return ("RENDER HERE...")
我尝试缓存但计数错误