【发布时间】:2022-01-16 21:25:38
【问题描述】:
我遇到了一个错误,我不知道为什么?在我的页面目录中,我有一个名为 contentslug 的文件夹,其中包含 [slug.js]。
我正在关注本教程 - https://www.youtube.com/watch?v=Mdx3ywlnzk8
这是slug.js中的代码
import Image from 'next/image'
import { documentToReactComponents } from '@contentful/rich-text-react-renderer';
export default function BlogPosts({ posts}) {
const {featuredImage, title , information } = posts.fields
return (
<div>
<div>
<Image
src={'https:' + featuredImage.fields.file.url}
width={featuredImage.fields.file.details.image.width}
height={featuredImage.fields.file.details.image.height}
/>
</div>
<div>
{documentToReactComponents(information)}
</div>
</div>
)
}
export async function getStaticProps({params}) {
const {items} = await client.getEntries({
content_type: 'posts',
'fields.slug': params.slug
})
return {
props: {posts: items[0], fallback: 'blocking'}
}
}
这是链接到它的组件
import Link from 'next/link'
export default function BlogPosts({post }) {
const {title, information, slug, thumbnail} = post.fields
return (
<div className="container text-center ">
<div>
<div>
<h4 className=''>{title}</h4>
<Link href={'/contentslug/' + slug}>
<a className='btn btn-primary text-white'>Read more</a>
</Link>
</div>
</div>
)
}
有什么想法吗?
【问题讨论】:
标签: javascript next.js contentful