You need to enable JavaScript to run this app. Next.js/React中如何用@prismicio/client传递timeline ref获取预览数据
优惠活动
大模型
产品
解决方案
定价
更多

Next.js/React中如何用@prismicio/client传递timeline ref获取预览数据

问题原因

你调用client.query时传入的参数名错误:@prismicio/client的查询方法接收预览ref的字段为ref,而非你使用的key,这就是报错信息中Unknown field key的来源。

修复方案

将你调用Prismic API的代码中参数的key字段替换为ref即可:

const client = Prismic.client(refApiUrl, {
    accessToken: apiToken,
});

const res: any = await client.query(predicates, {
    ref: refToken, // 将原来的key改为ref
});
额外优化提示
  • 你当前getServerSideProps中无token时直接返回console.warn的执行结果不符合Next.js要求的返回格式,建议调整为返回{ notFound: true }或者重定向到公开页面,避免触发Next.js的运行时错误。

内容的提问来源于stack exchange,提问作者Andrei Flavius

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.09 04:57:03