【发布时间】:2021-08-04 14:55:46
【问题描述】:
我有一份从 Firestore 中检索到的餐厅列表,单击餐厅名称后,我必须返回每个餐厅的详细信息页面。 在 ProductGrid 页面上,我已返回已存储在 firestore 中的所有餐厅,然后从每个餐厅名称中我应该转到 ProductDetail,其中将包含每个餐厅的详细信息(动态路由) 我已经创建了路线,但没有返回任何页面我无法弄清楚到底是什么问题! 这是通往productDetail页面的链接
ProductGrid.js
<h2> <Link to={`ecom-product-detail/${data.id}`}>{data.data.name_restaurant}</Link> </h2><<
ProductDetail.js
import { useParams } from "react-router-dom";
import { Link } from "react-router-dom";
import { firestore } from "../../../../../fire";
function ProductDetail(){
const {productId}= useParams();
const thisProduct = firestore.collection("Restaurants").doc().get.find((prod) => prod.id === productId);
return(
<div className="col-12">
<div className="card">
<h1>{thisProduct.name_restaurant}</h1>
<p> Price:${thisProduct.Currency}</p>
<p> {thisProduct.email} </p>
</div>
</div>
) ; }
export default ProductDetail;
Route.js
const Routes = () => {
const routes = [
{ url: "ecom-product-detail/:productId", component: ProductDetail },
];
return (
<Fragment>
<Switch>
{routes.map((data, i) => (
<Route
key={i}
exact
path={`/${data.url}`}
component={data.component}
/>
))}
</Switch>
{/* <Footer /> */}
</Fragment>
);
};
export default Routes;
【问题讨论】:
标签: javascript reactjs google-cloud-firestore react-router