【发布时间】:2022-01-13 23:25:12
【问题描述】:
我将首先显示代码并链接我正在关注的article。基本上我一直收到这个错误代码“/episode-one 还没有页面或功能”。有人可以告诉我我的文件路径有什么问题吗?我尝试使用文件夹结构来匹配文章,但没有任何改变。
这是 index.js 的代码
文件夹结构 - gatsby-contentful-site\src\episodes/src\episodes\podsode.js src\pages\EpisodeDetails
索引页面 {data.allContentfulPodcast.edges.map(slug => ${slug.node.slug}}>{slug.node.title} )}
gatsby node.js
const path = require("path")
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const response = await graphql(
`
query MyQuery {
contentfulPodcast {
slug
title
}
}
`)
response.data.allContentfulPodcast.edges.forEach(edge => {
createPage({
path: `/EpisodeDetails/${edge.node.slug}`,
component: path.resolve("./src/episodes/podsode.js"),
context: {
slug: edge.node.slug,
},
})
}) }
剧集详情
function EpisodeDetails ({props}) {
const data = useStaticQuery
(
graphql `
query {
allContentfulPodcast(sort: {fields: publishedDate, order: DESC}) {
edges {
node {
title
slug
}
}
}
}
`)
return (
<div>
{data.allContentfulPodcast.edges.map(edge =>
<h2>
<Link to={`/EpisodeDetails/${edge.node.slug}/`}>{edge.node.title}</Link>
</h2>
)}
</div>
)
}
export default EpisodeDetails
podsode.js
export const query = graphql`
query($slug: String!) {
contentfulPodcast(slug: { eq: $slug }) {
title
}
}
`
const podsode = props => {
return (
<div>
<h1>{props.data.contentfulPodcast.title}</h1>
</div>
)
}
export default podsode
【问题讨论】:
标签: reactjs graphql gatsby slug contentful