簡體   English   中英

React Router將ID傳遞給道具

[英]React Router pass id to props

我正在嘗試通過React Router傳遞頁面的ID,但是無法繞開應該怎么做。

鏈接在這里:

 <Link to={`/forum/${this.props.match.params.forumcatid}/${this.props.match.params.forumsubcatid}/${thread.subject}`} params={{ threadid: thread.id }}>{thread.subject}</Link> 

這是路由器:

 <Route exact={true} path="/forum/:forumcatid/:forumsubcatid/:forumthreadid" component={ForumThread} /> 

我嘗試了不同的方法,但是ID從未傳遞過。

我可以將其添加為URL的一部分,但是我不想要類似/ forum / 324234234/324234 /的URL,而是想要類似/ forum / category / thread /的URL

那么,如何才能以隱藏方式傳遞id,並將名稱保留在url中?

您可以通過查詢參數傳遞頁面ID。 就像“ mynextpage?pageId”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM