0

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?

MartinDK81
  • 343
  • 2
  • 8
  • 16

1 Answers1

0

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

  • Thanks man! If I pass it like that, it somehow becomes a state inside location, and then I can simply say: this.props.location.state.threadid – MartinDK81 Mar 16 '18 at 07:22