简体   繁体   中英

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.

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.

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/

So how can I pass the id in a hidden way, and keep the names in the url?

You can pass your page id through the query parameter. Like "mynextpage?pageId"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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