From 3544688b35c236496d0380b819d02040fa9aa03c Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 6 Dec 2018 21:40:43 +0000 Subject: [PATCH] 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 --- static/js/hashchange.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/static/js/hashchange.js b/static/js/hashchange.js index 288978b495..5f95713d52 100644 --- a/static/js/hashchange.js +++ b/static/js/hashchange.js @@ -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.