mirror of https://github.com/zulip/zulip.git
settings: Call replaceState() when entering settings/orgs.
We have an upcoming change that lets us use the back button after going arrowing through multiple settings pages. Without first adding this commit, we would have an infinite loop when you came back to '#settings' and then '#settings' would rewrite the url with the current hash. Just replacing the browser state allows the browser to do the right thing. The history protocol is pretty well supported: https://caniuse.com/#search=history
This commit is contained in:
parent
2a1a55af8a
commit
3544688b35
|
@ -182,6 +182,8 @@ function do_hashchange_overlay(old_hash) {
|
|||
if (base === 'settings') {
|
||||
if (!section) {
|
||||
section = settings_panel_menu.normal_settings.current_tab();
|
||||
var settings_hash = '#settings/' + section;
|
||||
exports.replace_hash(settings_hash);
|
||||
}
|
||||
|
||||
settings.launch(section);
|
||||
|
@ -191,6 +193,8 @@ function do_hashchange_overlay(old_hash) {
|
|||
if (base === 'organization') {
|
||||
if (!section) {
|
||||
section = settings_panel_menu.org_settings.current_tab();
|
||||
var org_hash = '#organization/' + section;
|
||||
exports.replace_hash(org_hash);
|
||||
}
|
||||
|
||||
admin.launch(section);
|
||||
|
@ -250,6 +254,17 @@ exports.update_browser_history = function (new_hash) {
|
|||
window.location.hash = new_hash;
|
||||
};
|
||||
|
||||
exports.replace_hash = function (hash) {
|
||||
if (!window.history.replaceState) {
|
||||
// We may have strange behavior with the back button.
|
||||
blueslip.warn('browser does not support replaceState');
|
||||
return;
|
||||
}
|
||||
|
||||
var url = get_full_url(hash);
|
||||
window.history.replaceState(null, null, url);
|
||||
};
|
||||
|
||||
exports.go_to_location = function (hash) {
|
||||
// Call this function when you WANT the hashchanged
|
||||
// function to run.
|
||||
|
|
Loading…
Reference in New Issue