简体   繁体   English

React Router将ID传递给道具

[英]React Router pass id to props

I'm trying to pass the id of a page through React Router, but can't wrap my head around how it should be done. 我正在尝试通过React Router传递页面的ID,但是无法绕开应该怎么做。

Here is the link: 链接在这里:

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

And here is the router: 这是路由器:

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

I've tried with different approaches, but the id is never passed. 我尝试了不同的方法,但是ID从未传递过。

I could just add it as a part of the URL, but I don't want an URL like /forum/324234234/324234/ Instead I want a nice url like so /forum/category/thread/ 我可以将其添加为URL的一部分,但是我不想要类似/ forum / 324234234/324234 /的URL,而是想要类似/ forum / category / thread /的URL

So how can I pass the id in a hidden way, and keep the names in the url? 那么,如何才能以隐藏方式传递id,并将名称保留在url中?

You can pass your page id through the query parameter. 您可以通过查询参数传递页面ID。 Like "mynextpage?pageId" 就像“ mynextpage?pageId”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM