Вопрос

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