我在处理 Nuxt 动态路由中的异步数据时遇到问题。
文件夹结构示例,
我的异步数据
async asyncData({context, error, req}) {
try {
const api = await Prismic.getApi(PrismicConfig.apiEndpoint, {req})
let document = []
const result = await api.getByUID('news', this.$route.params.slug)
document = result.results
return {
document,
documentId: result.id,
}
} catch (e) {
error({ statusCode: 404, message: 'Page not found' })
}
},
所以我总是以找不到 404 页面结束。我尝试了其他在正常“非动态路由”上正常工作的异步数据示例,它也返回 404。
我假设这是与 Nuxt 与组件的异步数据相关的问题,这是 Nuxt 将在 3.0 版中处理的问题?
但在那之前,如果你能帮我解决这个问题,我将不胜感激,我需要以某种方式完成这项工作。
我使用 Prismic 作为无头 API cms。