我发送的查询包含以下链接:
<Link to={{
pathname: `/forum/${this.state.mainCategoryName}/${category.name}`,
query: { subcatid: category.id} }
}
>
{category.name}
</Link>
这工作正常,我可以像这样呈现值:
this.props.location.query.subcatid
但是,只要我刷新页面或以某种方式以另一种方式进入页面(使用链接除外),查询就不会被包含。
我怎样才能做到这一点?
我的路由器看起来像这样:
<Route
exact={true}
path="/forum/:forumcatid/:forumsubcatid"
render={
(routeProps) => (
<ForumThreads {...routeProps} {...this.props} />
)
}
/>
答案 0 :(得分:0)
也许要与ComponentDidMount
内的ForumThreads
核实一下。在完整页面刷新之后,你没有pass
查询,它就在那里。
ComponentDidMount(){
// here check
// this.props.location.search
// to see if it allready contains some query strings inside url
// and then do your magic :)
}