문제

I am using the History.js framework and I only use the replaceState method.

My issue is about the replaceState behaviour, since it replaces all the querystring.

History.replaceState(null, null, "?tab=2");

So when I run the above code all parameters are erased and ?tab=2 is added :

www.yoursite.com/accounts?tab=2

Is it possible to maintain the other parameters unchanged except for the tab=2

www.yoursite.com/accounts?country=1&city=2&tab=2

도움이 되었습니까?

해결책

No, you will have to build that new querystring yourself.

function append(p) {
    return (location.search ? location.search+"&" : "?") + p; // + location.hash
}
history.replaceState(null, null, append("tab=2"));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top