【发布时间】:2020-09-13 10:27:26
【问题描述】:
我正在实施的内容:
我正在为一个项目使用 React(使用 Hooks)、React Router 和 Firebase,并且我想使用 documentId 作为单击文档时的 url。网址如下所示:https://website.com/view-companies/sdf920k1
App.js
<Route path="/view-companies/:documentId" component={ViewCompany} />
我的问题:
我已经在 App.js 中使用 :documentId 作为参数设置了我的 Route 路径,但我不确定要使用哪个钩子(useParams 或 useRouteMatch)以及我是否缺少某些东西设置。
当我查询 Cloud Firestore 并返回 7 个文档时,我想选择一个文档,并且在 url 中使用了 documentId。我已经尝试在 Github 上为 Firebase 寻找此设置的示例,但没有任何运气。
【问题讨论】:
标签: reactjs firebase google-cloud-firestore react-router react-router-dom