what i am trying to solve is, how to render to a specific page whenever user click to dynamic url? for more specific, there is my "product_list" api data. in "product_list" api data there is a key "url", whenever user click on this "url" then user will be redirect to another specific "product_detail" page. how to implement that specific dynamic url page to a specific page? so whenever user will click the url then user will see a specific UI page, not that dynamic url page.
i am probably new to reactjs. i am trying to solve this problem but i have no idea where i am doing thing wrong. it would be great if anybody could help me out what i am trying to solve is. thank you so much in advance.
// product_list api-data -->
[
{
"url": "http://localhost:8000/api/p/product01",
"id": 19,
"title": "product01",
"slug": "product01",
"description": "product01descc",
"image": "http://localhost:8000/media/google.com/images/tet0.png",
"price": 1,
"status": true,
"created_on": "2020-04-19T03:45:12Z"
},
{
"url": "http://localhost:8000/api/p/product02",
"id": 20,
"title": "product02",
"slug": "product02",
"description": "product01descc",
"image": "http://localhost:8000/media/google.com/images/tet0.png",
"price": 2,
"status": true,
"created_on": "2020-04-19T03:45:12Z"
}
]
product detail api-data of specific product list, for e.g "product-01".
{
"id": 19,
"title": "product01",
"slug": "product01",
"description": "product01descc",
"image": "http://localhost:8000/media/google.com/images/tet0.png",
"price": 1,
"created_on": "2020-04-19T03:45:12Z",
"status": true,
"color": 1,
"size": 1,
"product_category": []
}
my efforts to trying to solve this problem.
./src/productList.js
import React, {Component} from "react";
import Contacts from './productListHook.js';
export default class App extends Component{
state = {
contacts: [
]
}
contactList() {
fetch('http://localhost:8000/api/p_list')
.then(res => res.json())
.then((data) => {
this.setState({ contacts: data })
})
.catch(console.log)
}
render(){
return(
<Contacts contacts={this.state.contacts} />
)
}
}
in this page, whenever i am trying to rendering user, when user click to the "title" as you can see below. but that page rendering user to the api-detail page. obviously that would be cause i did not implement to that api-detail page to a specific page where user will see the UI detail page. how to do implement that in reactjs?
./src/productListHook.js
import React from 'react'
const Contacts = ({ contacts }) => {
return (
{contacts.map((contact) => (
<img src={contact.image} alt="" class="img-fluid" />
<h3> <a href={contact.url}>{contact.title}</a> </h3>
))}
)
};
export default Contacts