From 3faa875faec8cd0f32b5a6407f732f55302d6a9b Mon Sep 17 00:00:00 2001 From: Catouse Date: Thu, 4 Mar 2021 15:51:06 +0800 Subject: [PATCH] * support for going back between multi app tabs. --- module/index/js/index.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/module/index/js/index.js b/module/index/js/index.js index 0132a3c995..b6234ae83f 100644 --- a/module/index/js/index.js +++ b/module/index/js/index.js @@ -235,7 +235,7 @@ if(lastOpenedApp !== appCode) { lastOpenedApp = appCode; - updateAppUrl(appCode); + updateAppUrl(appCode, null, null, true); } return true; @@ -350,12 +350,13 @@ * @param {string} appCode The app code of target app to update url * @param {string|boolean} [url] The new url of the app * @param {string|boolean} [title] The new title of the app + * @param {boolean} [push] Use push instead of replace * @return {void} */ - function updateAppUrl(appCode, url, title) + function updateAppUrl(appCode, url, title, push) { var app = openedApps[appCode]; - if(!app) return; + if(!app || lastOpenedApp !== appCode) return; if(url) app.appUrl = url; else url = app.appUrl; @@ -363,11 +364,11 @@ else title = app.appTitle || app.text; if(url && url.indexOf('#') < 0 && getAppCodeFromUrl(url) !== appCode) url = url + '#app=' + appCode; - if(lastOpenedApp === appCode) + if(location.href !== url) { - if(location.url !== url) history.replaceState({app: appCode}, title, url); - document.title = title; + history[push ? 'pushState' : 'replaceState']({app: appCode}, title, url); } + document.title = title; } /* Bind helper methods to global object "$.apps" */ @@ -442,6 +443,11 @@ event.preventDefault(); }); + window.addEventListener('popstate', function(event) + { + if(lastOpenedApp !== event.state.app) openApp(event.state.app); + }); + /* Redirect or open default app after document load */ var defaultOpenUrl = window.defaultOpen; if(!defaultOpenUrl && location.hash.indexOf('#app=') === 0)