System Information
- Strapi Version: 4.3.2
- Operating System: Windows 10
- Database: PostGress
- Node Version: 16.16.0
- NPM Version:
- Yarn Version: 1.22.19
Hello I follow the tutorial create your “next” app using Next.js and strapi to working with slugified data
And i use the props {film.attributes.title} on an URL to show a movie list ( is okay )
And a second time to show the movie information. And i got the error
TypeError: Cannot read properties of null (reading 'attributes')
components>Film.js
import Link from "next/link";
const Films = ({ films }) => {
return (
<>
<ul className="list-none space-y-4 text-4xl font-bold mb-3">
{films &&
films.data.map((film) => {
return (
<li key={film.id}>
<Link href={`film/` + film.id}>{film.attributes.title}</Link>
</li>
);
})}
</ul>
</>
);
};
export default Films;
I use the same props on my uages>film>[slug].js file to show the movie name in the .
And when i’m on the url to see movie informations i got an error
TypeError: Cannot read properties of null (reading 'attributes')
pages>film>[slug].js
import Layout from "../../components/Layout";
import { fetcher } from "../../lib/api";
const Film = ({ film }) => {
return (
<Layout>
<h1 className="text-5xl md:text-6xl font-extrabold leading-tighter mb-4">
<span className="bg-clip-text text-transparent bg-radient-to-r from-blue-500 to-teal-400 py-2">
{film.attributes.title}
</span>
</h1>
</Layout>
);
};
export async function getServerSideProps({ params }) {
const { slug } = params;
const filmResponse = await fetcher(
`${process.env.NEXT_PUBLIC_STRAPI_URL}/films/${slug}`
);
return {
props: {
film: filmResponse.data,
},
};
}
export default Film;
Why i don’t get the same probleme on the url than show the movie list ?
How can i resolve the problem ?
Thanks