我有一些主要的路线作为我的基本页面,我用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'
我想把它改成这个"post.html?pnum=" + '3'
如果它是您尝试访问的相同组件,但只有使用不同的参数,这将导致您只更改页面内容,请考虑更改组件的state
。就像你的组件显示基于你的state
的元素。如果我没有误解,改变state
将有助于你的目的。
你需要倾听路径变化
componentWillReceiveProps(nextProps) {
if( this.props.location.search !== nextProps.location.search) {
// fetch new data...
}
然后组件将重新渲染。