I've created an array of elements that I've retrieved from the Wordpress REST API JSON object. I want to use react-router to make each element its own separate page using its id as the slug e.g. (/items/1).
I've hit a bit of a wall and haven't able to figure out how to dynamically create the routes using react-router. Any guidance would be much appreciated!!!
export default class ItemContainer extends React.Component {
constructor(){
super();
this.state= {
items: []
}
}
componentDidMount(){
var th = this;
this.serverRequest =
axios.get('http://website.com/wp-json/wp/v2/item/')
.then(function(result) {
th.setState({
officers: result.data
});
})
}
componentWillUnmount(){
this.serverRequest.abort();
}
render(){
const ItemComponents = this.state.items.map((item) => {
return <Item key={item.id} {...item} />;
});
return(
<div className="item-wrapper">
{ItemComponents}
</div>
);
}
}