It's because you have the same component rendering your posts. Your componentDidMount
runs only once and it is responsible for calling your api. You need to get the api logic in a different function and call it again in componentDidUpdate
.
I have done it in a codesanbox repo - https://codesandbox.io/s/musing-grass-sxokl
componentDidMount() {
if (!this.props.match) {
return;
} else {
this.callApi();
}
}
componentDidUpdate() {
this.callApi();
}
callApi = () => {
client
.getEntries({
content_type: "blogPost",
"fields.slug": this.props.match.params.slug
})
.then(response => {
console.log(response);
this.setState(
{
content: response.items[0].fields.content,
title: response.items[0].fields.title,
date: response.items[0].fields.date,
country: response.items[0].fields.country
},
() => console.log(this.state)
);
});
};
Hope this helps you.