我通过如下代码的addQuery
方法来更新查询参数:
import { hashHistory } from 'react-router';
/**
* @param {Object} query
*/
export const addQuery = (query) => {
const location = Object.assign({}, hashHistory.getCurrentLocation());
Object.assign(location.query, query);
hashHistory.push(location);
} ;
/**
* @param {...String} queryNames
*/
export const removeQuery = (...queryNames) => {
const location = Object.assign({}, hashHistory.getCurrentLocation());
queryNames.forEach(q => delete location.query[q]);
hashHistory.push(location);
} ;
先
addQuery( { id: 1 } )
执行完,查询参数更新成功,url
变成了/patch?id=1
;
然后
addQuery( { id: 2 } )
执行完,查询参数更新成功,url
变成了/patch?id=2
;
然后我通过浏览器的后退按钮,url是回退到了/patch?id=1
,可是视图的数据还是id为2的结果。
我期望的是id为1的数据,需要怎么操作?
我的react-router版本( 3.0.0 )
在github上看到类似问题:
1、View not updating on parameters change, only if reloaded
2、params prop does not reflect a change when redirecting to url with same route pattern but different url params