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:
Steve Howell 2018-12-06 21:40:43 +00:00 committed by Tim Abbott
parent 2a1a55af8a
commit 3544688b35
1 changed files with 15 additions and 0 deletions

View File

@ -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.