我有一些主要路线作为我的基本页面,并且通过XCTAssertEqual(handler.matchType!, MatchType.perfectMatch(0, 0))
的参数来更改内容,就像使用以下代码的GET
一样:
post.html?pnum=8
我有以下路线:
browserHistory = ReactRouter.browserHistory;
browserHistory.push("post.html?pnum=" + '8');
问题是当我通过路线更改时,它工作正常
但是当我仅更改<Router history={browserHistory}>
<Route path="/" component={RouteA} />
<Route path="index.html" component={RouteA} />
<Route path="me.html" component={RouteB} />
<Route path="post.html" component={RouteC} />
<Route path="tag.html" component={RouteD} />
<Route path="basket.html" component={RouteE} />
<Route path="*" component={vars.currentRoute} />
</Router>
的参数时,路径会更改,但页面上不会有任何更改。
我想这样做,例如:
当前路径为:browserHistory
我想将其更改为此"post.html?pnum=" + '8'
答案 0 :(得分:1)
您需要听
中的路径更改componentWillReceiveProps(nextProps) {
if( this.props.location.search !== nextProps.location.search) {
// fetch new data...
}
然后组件将重新呈现。
答案 1 :(得分:1)
如果您要使用的组件是同一组件,但只有不同的参数会导致您仅更改页面内容,请考虑更改组件的state
。就像您的组件根据您的state
来显示元素一样。如果我没有误会的话,更改state
会达到您的目的。