React Router 将 id 传递给 props
React Router pass id to props
我正在尝试通过 React Router 传递页面的 ID,但无法确定应该如何完成。
这里是 link:
<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
相反,我想要一个漂亮的 url 像这样 /forum/category/thread/
那么如何以隐藏的方式传递 id,并将名称保留在 url 中?
您可以通过查询参数传递您的页面 ID。
喜欢"mynextpage?pageId"
我正在尝试通过 React Router 传递页面的 ID,但无法确定应该如何完成。
这里是 link:
<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 相反,我想要一个漂亮的 url 像这样 /forum/category/thread/
那么如何以隐藏的方式传递 id,并将名称保留在 url 中?
您可以通过查询参数传递您的页面 ID。 喜欢"mynextpage?pageId"